Not able to post to my own twitter account using PHP OAuth and Abraham TwitterOAuth


#1

Can’t get oAuth to work to post messages to my own twitter account. I’ve set up my application, requested Read & write permissions, popped in all the correct values, and nothing is being posted to my twitter account… Here’s my code:

<?PHP
require_once ‘twitteroauth.php’;

define(“CONSUMER_KEY”, “Aof0w***…”);
define(“CONSUMER_SECRET”, “qtAHOMgeS***…”);
define(“OAUTH_TOKEN”, “731432660-X9kaxI91***…”);
define(“OAUTH_SECRET”, “66I6YjxsL1bDw4***…”);

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get(‘account/verify_credentials’);

$connection->post(‘statuses/update’, array(‘status’ => ‘test’));

?>


#2

For anyone else having this issue, here’s the answer:

Yeah, I figured out the problem. After requesting Read & Write permissions, you have to RECREATE your access tokens to reflect the new permissions. Once I popped in the new access tokens, everything worked fine. Thanks!


#3

Can you explain to me what files: ‘account/verify_credentials’ and ‘statuses/update’ point to? Are these in your site directory?


#4

Hey, I’m trying to do the same, but it doesn’t work. My code looks pretty much the same, I checked that the app has Read & Write access to the account, and copied the keys and everything.
Not tweeting. The script returns true though.


#5

Same problem here, everything looks fine, but still not able to tweet. Please suggest a solution.


#6

There are two things here that can stop a tweet.

  1. You are probably aware of this - but if you try to send the same information in a tweet - ie, if you keep sending
    "test" Then it will be blocked. you may have sent the first one, but any the same in a given period will be blocked.

  2. It could be an OAuth problem to do with the transition to 1.1. You need to trace each step, that is, have some code that displays what each step does as its doing it.
    Have debugging code that shows what is being returned from each step, including the ‘send tweet’ - which is the one you may be having trouble with. If the tweet is successful, you need to trap that return message.
    If SUCCESS return SuccessCode
    if FAIL return FailCode

I’m not familiar with PHP in this area - I use Actions Script 3, but the principal remains the same.

If you watch what each step of the process does, you will see what the Twitter interface is returning to you. and why.


#7

These are the twitter calls, and the full URL is probably in the requireonce() files.
In NON OAuth libraries, usually preceeded now by

https://api.twitter.com/1.1

eg:
urlRequest.url = _serviceHost+request;
var signedData:String = _oAuth.getSignedRequest(urlRequest.method, “https://api.twitter.com/1.1”+request, urlRequest.data as URLVariables);
urlRequest.data = new URLVariables(signedData);
return urlRequest;

private static const URL_PUBLIC_TIMELINE:String = "/statuses/public_timeline.json"; private static const URL_HOME_TIMELINE:String = "/statuses/home_timeline.json"; private static const URL_FRIENDS_TIMELINE:String = "/statuses/friends_timeline.json"; private static const URL_USER_TIMELINE:String = "/statuses/user_timeline"; private static const URL_RETWEETS_BY_ME:String = "/statuses/retweeted_by_me.json"; private static const URL_RETWEETS_TO_ME:String = "/statuses/retweeted_to_me.json"; private static const URL_RETWEETS_OF_ME:String = "/statuses/retweets_of_me.json"; private static const URL_SINGLE_TWEET:String = "/statuses/show/"; private static const URL_SEND_UPDATE:String = "/statuses/update.json"; private static const URL_DESTROY_TWEET:String = "/statuses/destroy/"; private static const URL_RETWEET:String = "/statuses/retweet/"; private static const URL_RETWEETS:String = "/statuses/retweets/"; private static const URL_MENTIONS:String = "/statuses/mentions.json"; private static const URL_FRIENDS:String = "/statuses/friends"; private static const URL_FOLLOWERS:String = "/statuses/followers"; private static const URL_USER_DETAILS:String = "/users/show.json?/"; // was just /show/ ref line 665 private static const URL_USER_SEARCH:String = "/users/search.json"; private static const URL_SINGLE_DIRECT_MESSAGE:String = "/direct_messages/show/"; private static const URL_RECEIVED_DIRECT_MESSAGES:String = "/direct_messages.json"; private static const URL_SENT_DIRECT_MESSAGES:String = "/direct_messages/sent.json"; private static const URL_SEND_NEW_DIRECT_MESSAGE:String = "/direct_messages/new.json"; private static const URL_DESTROY_DIRECT_MESSAGE:String = "/direct_messages/destroy"; private static const URL_CREATE_FRIENDSHIP:String = "/friendships/create/"; private static const URL_DESTROY_FRIENDSHIP:String = "/friendships/destroy/"; private static const URL_FRIENDSHIP_EXISTS:String = "/friendships/exists.xml"; private static const URL_FRIENDSHIP_SHOW:String = "/friendships/show.xml"; private static const URL_VERIFY_CREDENTIALS:String = "/account/verify_credentials.json"; private static const URL_RATELIMIT_STATUS:String = "/account/rate_limit_status.json"; private static const URL_UPDATE_PROFILE:String = "/account/update_profile.json"; private static const URL_UPDATE_PROFILE_COLORS:String = "/account/update_profile_colors.json"; private static const URL_UPDATE_PROFILE_IMAGE:String = "/account/update_profile_image.xml"; private static const URL_UPDATE_PROFILE_BG_IMAGE:String = "/account/update_profile_background_image.json"; private static const URL_RETRIEVE_FAVORITES:String = "/favorites"; private static const URL_CREATE_FAVORITE:String = "/favorites/create/"; private static const URL_DESTROY_FAVORITE:String = "/favorites/destroy/"; private static const URL_FOLLOW_USER:String = "/notifications/follow/"; private static const URL_UNFOLLOW_USER:String = "/notifications/leave/"; private static const URL_BLOCK_USER:String = "/blocks/create/"; private static const URL_UNBLOCK_USER:String = "/blocks/destroy/"; private static const URL_BLOCK_EXISTS:String = "/blocks/exists/"; private static const URL_BLOCKS:String = "/blocks/blocking.json"; private static const URL_BLOCK_IDS:String = "/blocks/blocking/ids.json"; private static const URL_END_SESSION:String = "/account/end_session.json"; private static const URL_SOCIAL_GRAPH_FRIEND_IDS:String = "/friends/ids"; private static const URL_SOCIAL_GRAPH_FOLLOWER_IDS:String = "/followers/ids"; private static const URL_REPORT_SPAM:String = "/report_spam.xml"; private static const URL_SAVED_SEARCHES:String = "/saved_searches.json"; private static const URL_RETRIEVE_SAVED_SEARCH:String = "/saved_searches/show/"; private static const URL_CREATE_SAVED_SEARCH:String = "/saved_searches/create.json"; private static const URL_DESTROY_SAVED_SEARCH:String = "/saved_searches/destroy/"; private static const URL_TWITTER_SEARCH:String = "http://search.twitter.com/search.atom"; private static const URL_TWITTER_TRENDS:String = "http://search.twitter.com/trends.json"; private static const URL_TWITTER_TRENDS_CURRENT:String = "http://search.twitter.com/trends/current.json"; private static const URL_TWITTER_TRENDS_DAILY:String = "http://search.twitter.com/trends/daily.json"; private static const URL_TWITTER_TRENDS_WEEKLY:String = "http://search.twitter.com/trends/weekly.json"; private static const DATA_FORMAT:String = "json"; // was xml

#8

You save me :slight_smile: … was having the same issue…


#9

fffff