最近,我读了一个不错的教程如何使用Twitter OAuth认证用户,即使它是在更改twitter格式之前编写的,但是它也适用于新的Twitter格式。
我有一些问题,请解释一下,如果有人成功的话。
getRequestToken和getAccessToken?是为了得到access token和access token secret吗?但这两种情况都已经在下面的页.http://dev.twitter.com/apps/{your_app_id}/my_token上给出了。
请求令牌和请求令牌秘密究竟需要什么?虽然我注意到,每次处理时,这两个令牌都不同。$connection->post( 'statuses/update', array('status' => 'some message got from text area value' );那么如何验证状态是否已成功更新??这意味着如果我想显示警告消息post has been sent successfully,我如何在我们的PHP页面实现它?
1. 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}
或
2.在我们的php代码(config.php)中定义的URL是否类似
define('OAUTH_CALLBACK', 'http://www.xyz.com');
再来一个Q'n
泰语更新
我按照你的建议做了下面的事
$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);以下回报
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.
)注意:为了安全起见,我隐藏了oauth_consumer key、oauth_nonce和oauth_token ;)
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
....
...我搞错了No status found with that ID,你提到的是哪个id_str??
发布于 2011-01-31 13:31:18
这个答案并不是专门针对亚伯拉罕的Twitter,而是适用于Twitter的OAuth API。
- You request the **request** token. It is only used for signing in, and cannot be used to access user's data. You will get the request token and request token secret. When requesting the request token, **you can specify a callback URL** which Twitter will send your users to when it is authenticated successfully.
- You need to keep the request token and secret until the authentication is done.
- After that, you redirect the user to `http://api.twitter.com/oauth/authorize?oauth_token=` followed by OAuth token.
- After the user signed in to Twitter and allowed your application, Twitter sends the user back to the callback URL.
- You exchange the request token for the access token, and you can then discard the request token because you won't need it anymore.只要您需要访问令牌,就可以保留它。如果不保留访问令牌,则需要再次请求请求令牌并将其交换为访问令牌,用户将不得不再次登录。
因此,基本上,如果您正在创建用户需要使用Twitter登录的内容,您需要执行上述所有步骤才能让用户注册。如果您只是为自己使用Twitter的API,则不需要身份验证步骤。使用您的访问令牌.
发布于 2011-01-21 06:15:58
因为只有在我们用验证器验证用户之后才能获得AccessToken和访问令牌秘密。
验证器在OAuth process.So中是最重要的,我们需要发送一个请求来生成AccessToken和访问令牌秘密。
在获得AccessToken和访问令牌秘密之后,我们可以在用户指定的时间内使用它,同时允许您的Twitter应用程序允许访问他的Info.it可能是1天,就像LInkedin OAuth中的wise一样,此后AccessToken和Access令牌秘密到期.
发布于 2011-01-31 12:39:59
当你做的时候你会得到什么:
$temp = $connection->post( 'statuses/update', array('status' => 'some message got from textarea value' );
print_r($temp);我猜这会将响应(以json/xml)格式存储在$temp var中。(要测试twitter响应,您可以检查http://dev.twitter.com/console)
在config.php中定义的回调url将确定它将被重定向到何处。这是因为这个回调参数最近被添加到twitter中。在此之前,您只能在twitter.com的App部分定义回调url,如果没有定义其他URL,则此url是默认的url。
https://stackoverflow.com/questions/4755933
复制相似问题