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 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM