如何将Twitter OAuth Echo更新为API v。1.1(PHP)
我有一个小应用程序,它将OAuth Echo与Tweetbot的自定义图像端点结合使用,将我发布到Twitter的媒体作为自己的主机。最近的API更新破坏了应用程序,我似乎找不到关于如何修复它的任何信息 以下是我在更新之前使用的类:如何将Twitter OAuth Echo更新为API v。1.1(PHP),oauth,twitter,twitter-oauth,Oauth,Twitter,Twitter Oauth,我有一个小应用程序,它将OAuth Echo与Tweetbot的自定义图像端点结合使用,将我发布到Twitter的媒体作为自己的主机。最近的API更新破坏了应用程序,我似乎找不到关于如何修复它的任何信息 以下是我在更新之前使用的类: // Twitter oAuth Echo Class // Author: http://shikii.net/blog/creating-a-custom-image-service-for-twitter-for-iphone/ class namespace
// Twitter oAuth Echo Class
// Author: http://shikii.net/blog/creating-a-custom-image-service-for-twitter-for-iphone/
class namespace_TwitterOAuthEcho
{
public $verificationUrl = "https://api.twitter.com/1/account/verify_credentials.json";
//isset($_SERVER['X-AUTH-SERVICE-PROVIDER']) ? $_SERVER['X-AUTH-SERVICE-PROVIDER'] : false;
public $userAgent = __CLASS__;
public $verificationCredentials;
/**
*
* @var int
*/
public $resultHttpCode;
/**
*
* @var array
*/
public $resultHttpInfo;
public $responseText;
/**
* Save the OAuth credentials sent by the Consumer (e.g. Twitter for iPhone, Twitterrific)
*/
public function setCredentialsFromRequestHeaders()
{
$this->verificationCredentials = isset($_SERVER['HTTP_X_VERIFY_CREDENTIALS_AUTHORIZATION'])
? $_SERVER['HTTP_X_VERIFY_CREDENTIALS_AUTHORIZATION'] : false;
}
/**
* Verify the given OAuth credentials with Twitter
* @return boolean
*/
public function verify()
{
$curl = curl_init($this->verificationUrl);
curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: ' . $this->verificationCredentials,
));
$this->responseText = curl_exec($curl);
$this->resultHttpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$this->resultHttpInfo = curl_getinfo($curl);
curl_close($curl);
return $this->resultHttpCode == 200;
}
}
作为一个twitterapi新手,我不确定要改变什么才能让它重新工作。文档自2012年8月以来一直没有更新过,所以这毫无帮助
Twitter的API 1.1概览页面确实这样说。好的我建立了一个新的应用程序;获取了我的消费者密钥/机密。然而,我不确定它们会去哪里。在Twitter上编辑应用程序设置时,我也不确定这里应该设置什么。我的应用程序(在我看来)实际上不需要与Twitter交互。我只是想把一个URL发送回Tweetbot(任何twitter客户端),这样它就可以把它放在tweet上
如果您能帮我更新,我们将不胜感激。谢谢。更换
public $verificationUrl = "https://api.twitter.com/1/account/verify_credentials.json";
with
public $verificationUrl = "https://api.twitter.com/1.1/account/verify_credentials.json";
就这样。您只需更改URL即可。你的twitter应用也不需要改变。它也可以与您的旧应用程序一起使用。替换
public $verificationUrl = "https://api.twitter.com/1/account/verify_credentials.json";
with
public $verificationUrl = "https://api.twitter.com/1.1/account/verify_credentials.json";
就这样。您只需更改URL即可。你的twitter应用也不需要改变。它同样适用于你的旧应用程序。这太简单了。谢谢你让我免于对我的代码进行大量完全不必要的变化测试。这太简单了。感谢您让我免于测试大量完全不必要的代码变体。