Yahoo php sdk getContacts()间歇性地工作

时间:2015-06-18 15:04:52

标签: php oauth-2.0 yahoo yahoo-api

我正在使用Yahoo! Social SDK来允许用户进行授权,然后获取其联系人列表。我已经设置了应用程序以允许读取联系人数据,并在验证时验证。

enter image description here

身份验证有效,因为我可以在每个页面加载时使用getProfile()配置文件。 getContacts()是问题,但95%的时间它返回false,这是不正确的。

我是否对请求令牌执行了错误,这意味着getContacts()没有正确的权限才能成功运行,或者雅虎是否在此查询中遇到某种奇怪的缓存问题?由于他们关于api和php的文档明显缺乏,这是更难的,是否有另一个新的库可以用来实现这个目标?我知道这是可能的,因为我可以在“AirBnb邀请朋友”网页上使用工作版本。

这是我正在使用的代码,它是使用CodeIgniter编写的,因此可以解释语法。

public function yahoo() {

    $oauthapp = new YahooOAuthApplication(DEV_OAUTH_CONSUMER_KEY, DEV_OAUTH_CONSUMER_SECRET, DEV_OAUTH_APP_ID, DEV_OAUTH_DOMAIN);

    if($this->session->userdata('yahoo_oauth_access_token')){

        $oauthapp->token = YahooOAuthAccessToken::from_string($this->session->userdata('yahoo_oauth_access_token'));

        $profile = $oauthapp->getProfile();
        $contacts = $oauthapp->getContacts(0, 1000);

        if($profile)
           print_r($profile);
        else
            echo "No profile / error";

        if($contacts)
           print_r($contacts);
        else
            echo "No contacts / error";

    }
    elseif(!$this->input->get()) {

        $request_token = $oauthapp->getRequestToken(DEV_OAUTH_DOMAIN);
        $this->session->set_userdata('request_token', json_encode($request_token));
        $redirect_url = $oauthapp->getAuthorizationUrl($request_token);

        redirect($redirect_url);
    }
    else {

        $request_token = json_decode($this->session->userdata('request_token'));
        $oauthapp->token = $oauthapp->getAccessToken($request_token, $this->input->get('oauth_verifier'));

        $this->session->set_userdata('yahoo_oauth_access_token', $oauthapp->token->to_string());

        redirect("/index/yahoo");
    }
}

1 个答案:

答案 0 :(得分:1)

经过长时间的长时间搜索后发现问题,几乎可以肯定会有其他人遇到同样的问题,因为它没有输出错误。

问题是库中的Curl超过10秒的运行时间,如果发生这种情况只是超时并且脚本结束。我的error_log中有错误但屏幕上没有任何内容。

如果您在YahooCurl.class.php中的第65行和第66行增加超时,则可以解决此问题。

  /**
   * Fetches an HTTP resource
   *
   * @param string $url    The request url
   * @param string $params The request parameters
   * @param string $header The request http headers
   * @param string $method The request HTTP method (GET, POST, PUT, DELETE, HEAD)
   * @param string $post   The request body
   *
   * @return string Response body from the server
   */
  public static function fetch($url, $params, $headers = array(), $method = self::GET, $post = null, $options = array())
  {
    $options = array_merge(array(
      'timeout'         => '10',
      'connect_timeout' => '10',
      'compression'     => true,
      'debug'           => true,
      'log'             => sys_get_temp_dir().'/curl_debug.log',
    ), $options);