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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制