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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭