【发布时间】:2018-03-02 01:17:06
【问题描述】:
我在我的 PHP 应用程序中使用 Hybridauth 3 代表我的帐户发布一些定期推文。 该应用程序具有所有可能的权限。当它在第一个身份验证步骤中要求它们时,我给予它所有权限。 之后 Twitter 将我重定向到指定的回调 URL,在那里我得到了一对 access_token 和 access_token_secret。 但是当我尝试使用这些令牌发布推文时 - 它给了我:
{"errors":[{"code":220,"message":"Your credentials do not allow access to this resource."}]}
以下是我尝试发布推文的方式:
$config = [
'authentication_parameters' => [
//Location where to redirect users once they authenticate
'callback' => 'https://mysite/twittercallback/',
//Twitter application credentials
'keys' => [
'key' => 'xxx',
'secret' => 'yyy'
],
'authorize' => true
]
];
$adapter = new Hybridauth\Provider\Twitter($config['authentication_parameters']);
//Attempt to authenticate the user
$adapter->setAccessToken(/*tokens I've got from getAccessToken() on /twittercallback/*/);
if(! $adapter->isConnected()) {
// never goes here, so adapter is connected
return null;
}
try{
$response = $adapter->setUserStatus('Hello world!');
}
catch (\Exception $e) {
// here I've got the error
echo $e->getMessage();
return;
}
尝试重新创建令牌和密钥\秘密对并多次通过应用程序的身份验证过程,包括输入我的 Twitter 帐户的密码(如 stackoverflow 上的一些帖子中所建议的那样),但仍然出现此错误。
附:根据this 的说法,Hybridauth 在最近的版本中已经修复了这个问题。
【问题讨论】:
标签: php twitter twitter-oauth hybridauth