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?