我使用 django 作为我的 Web 框架,
我发现python-social-auth是一个很好的 OAuth 包。
我还想从谷歌OAuth2访问谷歌驱动器。
我在Google Drive SDK上看到了一些示例代码:
from apiclient.discovery import build
def build_service(credentials):
http = httplib2.Http()
http = credentials.authorize(http)
return build('drive', 'v2', http=http)
所以,看起来我需要获取凭据来实例化服务器对象。
我该如何做才能获得凭据?
或者我该怎么做才能使用谷歌驱动器?
最佳答案
这非常有帮助,谢谢@eyscode! 我和@areyoueye遇到了同样的问题,结果在查看了Google代码后,结果需要被解码和depickle,然后它就工作得很好了! 下面是修改后的代码:
import pickle
...
storage = Storage(GoogleCredential, 'id', user, 'credential')
credentials = (pickle.loads(base64.b64decode(storage.get())))
...
然后执行 print(),您应该得到一个对象作为输出,如下所示:
...
print(credentials)
<oauth2client.client.OAuth2Credentials object at 0x7fa2837af630>
关于python - 如何获取 google Drive sdk 的 python-social-auth 凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20801229/