获取 Twitter 屏幕名称

3

我是OAuth的新手

我想知道如何使用"Abraham Wiliam的Twitter OAuth库"来获取用户的凭证信息,例如screen_name。

2个回答

6

下载这个库:https://github.com/abraham/twitteroauth。只需要 twitteroauth.phpOAuth.php 两个文件,其中仅需引入 twitteroauth.php 文件。

这是 Twitter 的示例代码:https://dev.twitter.com/docs/auth/oauth/single-user-with-examples#php

在声明 getConnectionWithAccessToken() 函数和 $connection 变量,并使用您的有效的应用程序令牌后,只需尝试以下代码

$user = $connection->get("account/verify_credentials");
print $user->screen_name;

根据这个Twitter REST API参考文档

1

我需要获取通过我的网站使用 Twitter 进行身份验证的特定用户的用户名,我有令牌。 - shan
看起来您想要使用OAuth认证方式调用此API方法:http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0verify_credentials。在Abraham的OAuth库中,index.php和test.php均有此方法的示例调用。 - Rup
我没有ID,我只有Twitter发送的令牌密钥。 - shan
如果您使用这些令牌对 http://api.twitter.com/1/account/verify_credentials.xml 进行身份验证请求,例如使用该库 $content = $connection->get('account/verify_credentials'); ,则可以得到用户信息。 - Rup

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接