drug95107 2015-06-18 15:04
浏览 44
已采纳

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

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.

enter image description here

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.

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.

This is the code I'm using, it's written using CodeIgniter so that explains the syntax.

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条回答 默认 最新

  • douzhang2680 2015-06-19 10:34
    关注

    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.

    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.

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理