Yahoo php sdk getContacts() 间歇性地工作 [英] Yahoo php sdk getContacts() intermittently works

查看:45
本文介绍了Yahoo php sdk getContacts() 间歇性地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Yahoo!社交 SDK 允许用户授权,然后获取他们的联系人列表.我已将应用设置为允许读取联系人数据,并在进行身份验证时进行验证.

I'm using the Yahoo! Social SDK to allow a user to authorize and then get a list of their contacts. I've setup the app to allow for the contact data to be read and this is verified when authenticating.

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

The authentication works because I can the profile using getProfile() on every single page load. The getContacts() is the problem though as 95% of the time it returns false which is not correct.

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

Am I doing something wrong with the request tokens that means getContacts() doesn't have the correct permission to run successfully or do Yahoo have some sort of strange caching issue with this query? It's even harder with the distinct lack of documentation from them regarding their api and php, is there another new library I can use to achieve this? I know it's possible because I can use a working version on the "AirBnb Invite a friend" webpage.

这是我正在使用的代码,它是使用 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");
    }
}

推荐答案

经过长时间的搜索终于找到了这个问题,几乎可以肯定会有其他人遇到同样的问题,因为它没有输出错误.

Finally found the issue after a long long search, almost certain there will be others with this same issue as it's got no error outputting.

问题是库中的 Curl 超过了 10 秒的运行时间,如果发生这种情况,它只是超时并且脚本结束.我的 error_log 中有错误,但屏幕上什么也没有.

The issue was Curl in the library exceeding the runtime of 10 seconds, if this happens it just timeouts and the script ends. There were errors in my error_log but nothing on screen.

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

If you increase the timeouts on line 65 and 66 in YahooCurl.class.php then this fixes the issue.

  /**
   * 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);

这篇关于Yahoo php sdk getContacts() 间歇性地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆