需要获得OAuth';流量';在Python上为googledrive提供独立的py应用程序

需要获得OAuth';流量';在Python上为googledrive提供独立的py应用程序,python,oauth-2.0,google-drive-api,credentials,Python,Oauth 2.0,Google Drive Api,Credentials,我需要获得OAuth2“流”,以便GoogDRIVE工作 以前,我已经获得了成功令牌的东西工作良好,但我需要有它设置,所以我不需要每次获得令牌,只要一次就可以了 以下是我所处的位置,基于: 这是一个独立的应用程序。那么首先,我的做法是否正确? 如果是这样,我如何在上面的else中以code的形式输入凭据?是的,这是一个简单的错误。以下是替换上述Q中位的工作剪: ...... if credentials is None: #step 1 auth_uri = flow.step

我需要获得OAuth2“流”,以便GoogDRIVE工作

以前,我已经获得了成功令牌的东西工作良好,但我需要有它设置,所以我不需要每次获得令牌,只要一次就可以了

以下是我所处的位置,基于:

这是一个独立的应用程序。那么首先,我的做法是否正确?
如果是这样,我如何在上面的
else
中以
code
的形式输入凭据?

是的,这是一个简单的错误。以下是替换上述Q中位的工作剪:

......
if  credentials is None:
    #step 1
    auth_uri = flow.step1_get_authorize_url() # Redirect the user to auth_uri
    print 'Go to the following link in your browser: ' + auth_uri
    code = raw_input('Enter verification code: ').strip()
    #step 2
    credentials = flow.step2_exchange(code)
else:
    print 'GDrive credentials are still current'

#authorise
http = httplib2.Http()
http = credentials.authorize(http)
print 'Authorisation successfully completed'
......etc

干杯

哦,天哪。这是一个小学生的错误!我想我需要做的就是把
#step2 credentials=flow.step2_exchange(code)
放在
if
语句中,而不是放在它后面。。。备用是否有一种方法可以静默地执行此操作,因为用户不必通过auth_uri获取auth_代码,应用程序本身可以获取代码并完成auth流
......
if  credentials is None:
    #step 1
    auth_uri = flow.step1_get_authorize_url() # Redirect the user to auth_uri
    print 'Go to the following link in your browser: ' + auth_uri
    code = raw_input('Enter verification code: ').strip()
    #step 2
    credentials = flow.step2_exchange(code)
else:
    print 'GDrive credentials are still current'

#authorise
http = httplib2.Http()
http = credentials.authorize(http)
print 'Authorisation successfully completed'
......etc