duanjie2940 2014-10-07 14:58
浏览 58

如何使用artdarek-oauth-4-laravel获取谷歌联系人列表?

I am using artdarek-oauth-4-laravel for the Login to my website via Facebook, twitter and google.

Login part is working fine. But I want to get some more data from these api, like if user is registering through the google then I am looking for their general info as well as google contact list, or if the user is registering from Facebook then I am trying to get the /me and /friend-list etc.

Here, I am just taking the case of google.

I have set the config like this

   'Google' => array(
        'client_id'     => '***********************************',
        'client_secret' => '***********************************',
        'scope'         => array('userinfo_email', 'userinfo_profile', 'https://www.google.com/m8/feeds/'),
    ),

My Controller Function is this:-

   public function loginWithGoogle()
   {
       $code = Input::get( 'code' );

       $googleService = OAuth::consumer( 'Google' );
       if ( !empty( $code ) )
       {
          $token = $googleService->requestAccessToken( $code );
      //  $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );
          $result = json_decode( $googleService->request( 'https://www.google.com/m8/feeds/contacts/default/full' ), true );
          echo json_encode($result);

       }
       else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to google login url
         return Redirect::to( (string)$url );
       }
   }

This code leads me to the google api and asks for all the permission that I have set in the scope of the service. Here once I got the access token after exchanging the code parameter with the api, I am calling the url to return me the contact list but it fails. And I am getting this message from the laravel :-Failed to request resource.

If I call the commented $result request, it returns me the result.

So, I wanted to know how can we use this library for the data other than login and register. In case of retrieving facebook friendlist the same thing happens but the login works. (My Facebook App has the permission to get friendlist).

Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • dpl74687 2014-10-21 15:29
    关注

    Check this response, https://stackoverflow.com/a/26488136/434790.

    It worked for me. The culprit: alt=json to be added to https://www.google.com/m8/feeds/contacts/default/full

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法