PHP Classes

Twitter Status Update Error

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  Twitter Status Update Error  >  (Un) Subscribe thread alerts  
Subject:Twitter Status Update Error
Summary:Error on status update with twitter
Messages:4
Author:Ecxzqute Rhaiga
Date:2013-07-05 21:24:45
Update:2013-07-06 11:45:59
 

  1. Twitter Status Update Error   Reply   Report abuse  
Picture of Ecxzqute Rhaiga Ecxzqute Rhaiga - 2013-07-05 21:24:45
Hi Manuel,

I am trying to use your api to update user status and have followed your twitter example but I am stucked with an error.

Here's the code I am using

<?php

error_reporting(E_ALL);
require('http.php');
require('oauth_client.php');

$client = new oauth_client_class;
$client->debug = 1;
$client->debug_http = 1;
$client->server = 'Twitter';
$client->redirect_uri = 'https://'.$_SERVER['HTTP_HOST'].
dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/share_on_twitter.php';

//twtr
$client->client_id = 'twitter_id_here..'; $application_line = __LINE__;
$client->client_secret = 'twitter_secret_here';


if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Please go to Twitter Apps page https://dev.twitter.com/apps/new , '.
'create an application, and in the line '.$application_line.
' set the client_id to Consumer key and client_secret with Consumer secret. '.
'The Callback URL must be '.$client->redirect_uri);

if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
/*$success = $client->CallAPI(
'https://api.twitter.com/1.1/account/verify_credentials.json',
'GET', array(), array('FailOnAccessError'=>true), $user);*/

//Tweet

$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update"
,'POST'
,array('status'=>'This is a test tweet to evaluate the PHP OAuth API support update twitter status sent at '.strftime("%Y-%m-%d %H:%M:%S")
,array('FailOnAccessError'=>true)
), $user);


}
}
$success = $client->Finalize($success);
}

if($client->exit)
exit;

if($success)
{
echo 'success?';
}
else{
echo 'failed!??';
}

echo "<pre>";print_r($client);echo "</pre>";

?>


And here's the debug output:

[debug_output] => OAuth client: Checking the OAuth token authorization state
OAuth client: The OAuth token was already authorized
OAuth client: Accessing the API call at https://api.twitter.com/1.1/statuses/update
OAuth client: Could not retrieve the OAuth access token. Error: it was not possible to access the API call: it was returned an unexpected response status 401 Response:

And here are the errors inside $client

[access_token_error] => it was not possible to access the API call: it was returned an unexpected response status 401 Response:
[authorization_error] =>
[response_status] => 401


it says that "The OAuth token was already authorized" but why is it that I am having an "access_token_error"?

Where did I go wrong?

  2. Re: Twitter Status Update Error   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-07-06 02:06:53 - In reply to message 1 from Ecxzqute Rhaiga
You probably need to create an application that has write permissions to post in the user timeline.

Go in https://dev.twitter.com/apps and check the Twitter application you created. If the Access level value is set to read-only, you cannot use that application for posting in the user timeline.

In that case you need to create a new application with write permissions.


  3. Re: Twitter Status Update Error   Reply   Report abuse  
Picture of Ecxzqute Rhaiga Ecxzqute Rhaiga - 2013-07-06 03:45:46 - In reply to message 2 from Manuel Lemos
Sorry to have forgotten to include twitter app settings in my previous post.

Yes, I have set my twitter app to have Read, Write and Access direct messages permissions.

From Application Details

OAuth settings

Access level Read, write, and direct messages


Your access token

Access token 111811793-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Access token secret WXEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Access level Read and write

  4. Re: Twitter Status Update Error   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2013-07-06 11:45:59 - In reply to message 3 from Ecxzqute Rhaiga
There was a bug that was preventing to set the access token secret. The bug is fixed and the new version was just uploaded. Just let me know if that does not address your problem.