|
Shad - 2013-05-29 18:36:10
Hello,
sorry for my english.
Thanks for the class. It's great!
I'm trying to publish a new status on twitter but I don't understand how to use access_token and access_token_secret.
I think need to set the $scope attribute, but do not know where to retrieve it. Can you help me please?
Shad
Manuel Lemos - 2013-05-30 00:47:06 - In reply to message 1 from Shad
Once you call the Process file to get the authorization from a user, the class will set the access_token and access_token_secret variables.
You should store those values in a database table associating with the user in your system.
Later, before you call the API, just set the access_token and access_token_secret variables from the values stored in a database.
Shad - 2013-05-30 07:35:24 - In reply to message 2 from Manuel Lemos
Hi,
first of all, thanks for the reply.
I try to set access_token and access_token_secret with the values ​​that I read on my application on twitter but does not work.
I do not have set the attribute $scope?
Here is the function that I use with an ajax call:
<?php
require_once DIR_LAVORO . 'include/social/http.php';
require_once DIR_LAVORO . 'include/social/oauth_client.php';
function pubblicaTwitter($testo)
{
try
{
$client = new oauth_client_class;
$client->debug = 1;
$client->debug_http = 1;
$client->server = 'Twitter';
$client->redirect_uri = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$client->client_id = TWITTER_CONSUMER_KEY; // from my twitter APP
$client->client_secret = TWITTER_CONSUMER_SECRET; // from my twitter APP
$client->scope = ''; // ???
$client->access_token = TWITTER_ACCESS_TOKEN; // from my twitter APP
$client->access_token_secret = TWITTER_CONSUMER_SECRET; // from my twitter APP
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update.json",
'POST',
array(
'status' => $testo
),
array(),
$user
);
}
}
$success = $client->Finalize($success);
}
}
catch(Exception $e)
{
throw $e;
}
}
?>
where am I wrong?
Thanks!
Shad - 2013-05-30 10:29:17 - In reply to message 3 from Shad
I think the problem might be the constants TWITTER_ACCESS_TOKEN and TWITTER_CONSUMER_SECRET.
I've turned into variables and I added this line to the beginning to read from the configuration file:
global $TWITTER_ACCESS_TOKEN, $TWITTER_ACCESS_TOKEN_SECRET;
but I still have some doubts about the operation.
I hope that's good, because now I have to do it for Facebook too.
Give me confirmation that the code I wrote is right please.
Thanks again!
Manuel Lemos - 2013-06-03 12:56:58 - In reply to message 3 from Shad
You should not be setting the access_token and access_token_secret from constants.
Those values are retrieved by the class from the OAuth server as result of the OAuth authorization process.
You could set those values later if you have first authorized the user, saved the tokens in a database, and restored them just to send API calls with the CallAPI function. In that case you should not call the Process function.
Shad - 2013-06-03 20:21:28 - In reply to message 5 from Manuel Lemos
This is my last version of the function. Do you think is right?
function pubblicaTwitter($testo)
{
try
{
global $TWITTER_ACCESS_TOKEN, $TWITTER_ACCESS_TOKEN_SECRET;
$client = new oauth_client_class;
$client->debug = IS_DEBUG;
$client->debug_http = IS_DEBUG;
$client->server = 'Twitter';
$client->redirect_uri = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$client->client_id = TWITTER_CONSUMER_KEY;
$client->client_secret = TWITTER_CONSUMER_SECRET;
$client->access_token = $TWITTER_ACCESS_TOKEN;
$client->access_token_secret = $TWITTER_ACCESS_TOKEN_SECRET;
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update.json",
'POST',
array(
'status' => $testo
),
array(),
$user
);
}
}
$success = $client->Finalize($success);
}
}
catch(Exception $e)
{
throw $e;
}
}
Manuel Lemos - 2013-06-03 23:37:07 - In reply to message 6 from Shad
No, stop assigning the access_token and access_token_secret variables. I already explained why above.
mr snow - 2013-08-29 03:28:27 - In reply to message 6 from Shad
Hi Shad. I know what you are trying to do. The problem is that calling Process overwrites your token and secret.
To test just replace your process line with a truth statement
replace
if(($success = $client->Process()))
with
if(true)
But as Manuel mentions the tokens shouldn't be in code. They should be in a database somewhere.
|