doushan7077 2013-09-03 07:48
浏览 132
已采纳

Google Drive API使用Google +授权登录

I have implemented google drive api in my website(in php) with the Oauth 2 authorizing method where different users have to enter their own client id and client secret to access files in his/her google drive.

But to make it more user friendly I am planning to implement Google+ Sign-in method as in this url https://developers.google.com/drive/about-auth.

Can anyone provide me with a tutorial on how to use google + sign in to get the refresh token for google drive api requests?

  • 写回答

1条回答 默认 最新

  • doupin8555 2013-09-03 08:17
    关注

    These are the steps ...

    1. Call the auth URL with your app/client ID and the scopes you require. Include the "email" scope.

    2. Google will walk the user through login the and (if the first time through) authorisation dialogues

    3. Eventually the browser will redirect back to your oauthcallback url, and pass you an auth code
    4. Call google to convert the auth code to a refresh token. This will also return the user's google ID and an access token.
    5. Store the user ID in your session so you can identify the user subsequently
    6. Persist the refresh token alongside the google user id in a database

    On subsequent visits...

    1. If you have the google user id in the your session, you can retrieve the refresh token from your database and use it to generate access tokens as you need them.
    2. If you do NOT have the google user id in your session, go through the steps above. This time, google will NOT prompt the user for authorisation (since it's already authorised), and the refresh token will be blank (since you already have one stored).

    Everything you need to know is within the oauth playground page. If you click through the buttons, you will see that it is following the steps I outlined above.

    You then need to deal with the possible error situations, eg

    • user declines permission
    • user withdraws permission
    • google expired the refresh token (happens a lot) so you need to re-auth
    • timeouts
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误