简体   繁体   English

我如何认证Twitter用户?

[英]How can i authenticate the twitter user?

I am an absolute beginner on Twitter API. 我绝对是Twitter API的初学者。 I want redirect user to login dialog page and authenticate the user. 我希望重定向用户登录对话框页面并验证用户身份。 I am looking for an sample code which authenticate twitter user and i could not find any. 我正在寻找验证Twitter用户身份的示例代码,但我找不到任何示例。 And i think Twitter documentation isn't so good. 而且我认为Twitter文档不是很好。

require 'twitteroauth/twitteroauth.php';

$consumer_key = 'xxx';
$consumer_secret = 'xxx';
$access_token = 'myUserID-xxx';
$access_tokan_secret = 'xxx';


$twitter = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_tokan_secret);

$twitter->post('https://api.twitter.com/1.1/statuses/update.json?status=some post');

Even if anybody different from me runs this code it posts to my timeline as it should be. 即使与我不同的人都运行此代码,它也会按原样发布到我的时间轴中。 Because this is admin's access token and there is myUserID. 因为这是管理员的访问令牌,所以有myUserID。 So, how can i redirect user to login page which asks for some permissions? 那么,如何将用户重定向到要求某些权限的登录页面? Read, Write and Access direct messages section is selected in my app settings. 在我的应用程序设置中选择了“读取,写入和访问直接消息”部分。

For list of twitter libraries: https://dev.twitter.com/docs/twitter-libraries 有关Twitter库的列表: https : //dev.twitter.com/docs/twitter-libraries

Personally, I've successfully used the tmhOAuth library for PHP: https://github.com/themattharris/tmhOAuth 就个人而言,我已经成功地将tmhOAuth库用于PHP: https : //github.com/themattharris/tmhOAuth

Check out oauth_authorize_flow.php for good example of the OAuth flow you are trying to produce: https://github.com/themattharris/tmhOAuthExamples/blob/master/web/oauth_authorize_flow.php 请查看oauth_authorize_flow.php,以获取您尝试生成的OAuth流程的好示例: https : //github.com/themattharris/tmhOAuthExamples/blob/master/web/oauth_authorize_flow.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM