Recently I read a nice tutorial How to Authenticate Users With Twitter OAuth even it written before changing twitter ID format but it works with the new Twitter ID Format too.
I have some questions , please explain if anybody done it successfully..
Why we always call two method getRequestToken
and getAccessToken
? Is it to get access token
and access token secret
? but both are already given at below page...
http://dev.twitter.com/apps/{your_app_id}/my_token.
what is the exactly need of request token and request token secret?? although i notice that both token comes different each time we process.
if we update our status from below method
$connection->post( 'statuses/update', array('status' => 'some message got from text area value' );
Then how do we verify that status has been updated successfully?? It means if i want to display alert message post has been sent successfully
, how do i implement that in our PHP page??
which callback URL is important, i.e. where actually user is navigated after posting or doing stuff on twitter?
is it the URL Registered OAuth Callback URL
which is written at the time of developing an application on
http://dev.twitter.com/apps/{id_no}
or
is it the URL which is defined in our php code (config.php
) like
define('OAUTH_CALLBACK', 'http://www.xyz.com');
i did below according to your suggestion
$user_info = $connection->get('account/verify_credentials');
$status_info =$connection->get('statuses/show/', array('id' =>32320907720523776) );
echo "<pre>";
print_r($status_info);
echo "</pre> Content : <pre>";
print_r($user_info);
returns below
stdClass Object
(
[request] => /1/statuses/show.json?id=3.2320907720524E%2B16&oauth_consumer_key=jashak..&oauth_nonce=bec...&oauth_signature=%2FMj%2B0Z7oyYNKdMn%2B%2FOJ6Ba8ccfo%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1296541384&oauth_token=223961574-cW4...&oauth_version=1.0a
[error] => No status found with that ID.
)
note: i hide the oauth_consumer key
,oauth_nonce
and oauth_token
for security purpose ;)
Content:
stdClass Object
(
[follow_request_sent] =>
[profile_link_color] => 038543
[profile_image_url] => http://a3.twimg.com/profile_images/1215444646/minialist-photography-9_normal.jpg
[contributors_enabled] =>
[favourites_count] => 31
[profile_sidebar_border_color] => EEEEEE
[id_str] => 223961574 // this is also id_str
[status] => stdClass Object
(
[retweeted] =>
[id_str] => 32320907720523776 // this id_str i used
[in_reply_to_status_id_str] =>
[geo] =>
[contributors] =>
[source] => Black Noise
[in_reply_to_user_id_str] =>
[retweet_count] => 0
[truncated] =>
[coordinates] =>
[created_at] => Tue Feb 01 06:14:39 +0000 2011
[favorited] =>
[text] => Twitter test: verify that status has been updated
[place] =>
[in_reply_to_screen_name] =>
[in_reply_to_status_id] =>
[id] => 3.2320907720524E+16
[in_reply_to_user_id] =>
)
[screen_name] => ltweetl
[profile_use_background_image] => 1
....
...
i got error No status found with that ID
and which id_str
u r mentioning??
Most of Twitter's Enterprise APIs require HTTP Basic Authentication. This consists of a valid email address and password combination passed as an authorization header for each API request.
These tokens do not expire but can be revoked by the user at any time. Twitter allows you to obtain user access tokens through the 3-legged OAuth flow, which allows your application to obtain an access token and access token secret by redirecting a user to Twitter and having them authorize your application.
The API Key and Secret (also known as Consumer Key and Secret) are the most fundamental credentials required to access the Twitter API. These credentials act as the username and password for your Twitter App, and are used by the Twitter API to understand which App requests are coming from.
This answer is not specifically for Abraham's Twitter-OAuth API, but applies to Twitter's OAuth API in general.
That page only gives you your access token and access token secret to your own apps. This is fine if you don't need your app to be authenticated as any other users, so no need to request request tokens and no need to exchange the request token for access token, you just use your access token
However, if you want to authenticate as other users, you will have to go through all the required steps, which is explained in short here:
http://api.twitter.com/oauth/authorize?oauth_token=
followed by OAuth token.You can keep the access token as long as you need it. If you don't keep the access token, you will need to request the request token and exchange it for access token again, and your users will have to sign in again.
So basically, if you are creating something that the user needs to sign in using Twitter, you need to do all the steps above to get the user signed in. If you are just using Twitter's API for yourself, you don't need the authentication step. Use your access token.
You can check for the tweet's ID by checking for the id_str
key on the returned response.
If the status isn't posted, Twitter will return an error object.
You can specify the default OAuth callback in the application settings page, which will be used when you don't explicitly specify a callback.
This is required because if you somehow forget to or did not specify a callback URL, Twitter will still know where to redirect your users to.
However, Twitter encourages that you should explicitly specify a callback URL. There are many benefit from using a callback URL, such as being able to specify any URLs as the callback. I used to benefit from this one because my Twitter client runs on two different domains, I could redirect the users back to the right place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With