2013-03-15 52 views
0

我有一个小型应用程序,它使用(使用)OAuth Echo与Tweetbot的自定义图像端点一起自我托管我发布到Twitter的媒体。最近的API更新已经打破了应用程序,我似乎无法找到任何有关如何解决它的信息。如何将Twitter OAuth Echo更新为API 1.1版(PHP)

下面是我用的是更新前等级:

// 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; 
    } 
} 

作为Twitter的API新手,我不是一定要改变什么让它再次合作。 Twitter's OAuth Echo文档自2012年8月以来未更新,因此没有任何帮助。

Twitter的API 1.1概述页确实说all endpoints now require authorization。精细。我建立了一个新的应用程序;拿到了我的消费者钥匙/秘密。但是,我不确定那些人去哪里。在Twitter上编辑应用程序设置时,我也不确定应该在这里设置什么设置。我的应用程序没有(在我看来)实际上需要与Twitter进行交互。我只是试图发回一个URL到Tweetbot(任何Twitter客户端),所以它可以将它放在推文中。

获得此更新的任何帮助将不胜感激。谢谢。

回答

3

更换

public $verificationUrl = "https://api.twitter.com/1/account/verify_credentials.json"; 

with 

public $verificationUrl = "https://api.twitter.com/1.1/account/verify_credentials.json"; 

完蛋了。您只需要更改网址。也没有必要改变你的twitter应用程序。它也会与你的旧APP一起工作。

+0

这简直令人尴尬。感谢您节省我测试我的代码的各种完全不必要的变化。 – Shelton 2013-03-15 18:21:16