【问题标题】:How to update Twitter OAuth Echo to API v. 1.1 (PHP)如何将 Twitter OAuth Echo 更新到 API v. 1.1 (PHP)
【发布时间】:2013-03-04 10:31:58
【问题描述】:

我有一个小型应用程序,它使用(使用)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_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 客户端),以便它可以将它放在推文中。

我们将不胜感激任何有关更新此内容的帮助。谢谢。

【问题讨论】:

    标签: oauth twitter twitter-oauth


    【解决方案1】:

    替换

    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。您的推特应用程序也无需更改。它也适用于您的旧 APP。

    【讨论】:

    • 这太简单了。感谢您使我免于对我的代码进行大量完全不必要的变体测试。
    猜你喜欢
    • 2014-08-06
    • 2013-07-21
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    相关资源
    最近更新 更多