Update upload_with_media php (Matt Harris library) to include sign-in tokens (from Abraham library)


#1

Does anyone know how to update the upload_with_media php code from the Matt Harris library (below) to include the Oauth_token and Oauth_token_secret from a sign-in page using the Abraham library? Both of the codes are working fine separately but adding the token and secret to the update_with_media php is proving difficult. Thanks

<?php
//start session
session_start();

//just simple session reset on logout click
if(isset($_GET[“reset”]) && $_GET[“reset”]==1)
{
session_destroy();
header(‘Location: ./forms/check.php’);
}

// Include config file and twitter PHP Library by Abraham Williams (abraham@abrah.am)
include_once(“config.php”);
include_once("…/twitteroauth.php");
?>

<? require '.../tmhOAuth.php'; require '.../tmhUtilities.php'; if(isset($_SESSION['status']) && $_SESSION['status']=='verified') { //Success, redirected back from process.php with varified status. //retrive variables $screenname = $_SESSION['request_vars']['screen_name']; $twitterid = $_SESSION['request_vars']['user_id']; $oauth_token = $_SESSION['request_vars']['oauth_token']; $oauth_token_secret = $_SESSION['request_vars']['oauth_token_secret']; } $tmhOAuth = new tmhOAuth(array( 'consumer_key' => 'XXXXX', 'consumer_secret' => 'XXXXX', 'user_token' => $oauth_token, 'user_secret' => $oauth_token_secret, )); $params = array( 'image' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}", ); $code = $tmhOAuth->request( 'POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array( 'media[]' => "@{$image};type=image/jpeg;filename={$image}", 'status' => " " . $status ), true, // use auth true // multipart ); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr($tmhOAuth->response['response']); } ?>

#2

Can you be more specific about what isn’t working?


#3

Yeah sure…the above code was working just fine before the last blackout and switch to API 1.1 by Twitter…so I could sign into my site with a twitter account, that account was then directed to a page with the above code where I could tweet an image and text.

However I now receive the following error {“errors”:[{“message”:“Bad Authentication data”,“code”:215}]}?? I have another page for tweets only (no image) which works fine…but it uses your code and not the code above which is mostly from themattharris library, full code below. I’ve downloaded the the latest version of your library and that from themattharris and updated the posting url to 1.1 but I still get the same error? Any help would be great. Thanks

<?php //start session session_start();

//just simple session reset on logout click
if(isset($_GET[“reset”]) && $_GET[“reset”]==1)
{
session_destroy();
header(‘Location: ./thepage.php’);
}

// Include config file and twitter PHP Library by Abraham Williams (abraham@abrah.am)
include_once("…/config.php");
include_once("…/twitteroauth.php");
?>

<? require '..../tmhOAuth.php'; require '..../tmhUtilities.php'; if(isset($_SESSION['status']) && $_SESSION['status']=='verified') { //Success, redirected back from process.php with varified status. //retrive variables $screenname = $_SESSION['request_vars']['screen_name']; $twitterid = $_SESSION['request_vars']['user_id']; $oauth_token = $_SESSION['request_vars']['oauth_token']; $oauth_token_secret = $_SESSION['request_vars']['oauth_token_secret']; $tmhOAuth = new tmhOAuth(array( 'consumer_key' => 'XXXXX', 'consumer_secret' => 'XXXXX', 'user_token' => $oauth_token, 'user_secret' => $oauth_token_secret, )); $params = array( 'image' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}", ); $code = $tmhOAuth->request( 'POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json ', array( 'media[]' => "@{$image};type=image/jpeg;filename={$image}", 'status' => " " . $status ), true, // use auth true // multipart ); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr($tmhOAuth->response['response']); } } ?>