0

削除したいくつかの機能を使用して Oauth2 トークンを取得しています: https://code.google.com/p/google-api-python-client/source/browse/#hg%2Foauth2client

私は試した:

yt_service              = gdata.youtube.service.YouTubeService()
yt_service.developer_key    = YOUTUBE_DEV_KEY
yt_service.access_token     = FRESH_OAUTH2_ACCESS_TOKEN
yt_service.client_id    = YOUTUBE_OAUTH2_CLIENT_ID
yt_service.email            = YOUTUBE_USER_EMAIL
yt_service.password         = YOUTUBE_USER_PASSWORD
yt_service.source           = YOUTUBE_DEV_SRC
yt_service.ProgrammaticLogin()

GetFormUploadTokenしかし、 callまたはを適切に取得する方法がわかりませんUpdateVideoEntry。以前は a だけを使用してdeveloper_keyいましたが、動作していました ( を使用gdata.youtube.service.YouTubeService())。

私もこの例を使用してみましたが、コメントがあまりなく、ドキュメントも良くありませんでした: https://code.google.com/p/youtube-api-samples/source/browse/samples/python/ update_video.py

簡単に変えてみました build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, http=credentials.authorize(httplib2.Http()))

build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, ACCESS_TOKEN=current_access_token)

しかし、それが何であるかわからないと不平を言うだけACCESS_TOKENです。

4

1 に答える 1

0

これが私がやっている方法です。

def _yt_oauth_flow_hack(self, secret_json_str, scope, redirect_uri=None):
    """
    A hacked version of: oauth2client.clientflow_from_clientsecrets
    """
    client_type, client_info = clientsecrets.loads(secret_json_str)
    if client_type in [clientsecrets.TYPE_WEB, clientsecrets.TYPE_INSTALLED]:
        return OAuth2WebServerFlow(
            client_info['client_id'],
            client_info['client_secret'],
            scope,
            redirect_uri=redirect_uri,
            user_agent=None,
            auth_uri=client_info['auth_uri'],
            token_uri=client_info['token_uri']
        )        
def begin_authentication(self):
    '''Starts the authentication process and returns the URL that we have to use to authorize the content
    if we need to authorize it, otherwise will generate the service and return None'''

    credentials = self._storage.get()
    if credentials is None:
        print 'Credentials Not Stored - We Require Fresh Authentication'
        flow = self._yt_oauth_flow_hack(AUTH_JSON, self.scope)
        flow.redirect_uri = OOB_CALLBACK_URN
        return flow.step1_get_authorize_url()
    elif (credentials.invalid or credentials.token_expiry <= (datetime.now() + timedelta(seconds=time.timezone))):
        print 'Credentials are Expired - Going to attempt to refresh them'
        try:
            http = httplib2.Http()
            credentials.refresh(http)
            print 'Success!'
        except AccessTokenRefreshError:
            print 'Unable to refresh credentials - requesting new ones.'
            flow = self._yt_oauth_flow_hack(AUTH_JSON, self.scope)
            flow.redirect_uri = OOB_CALLBACK_URN
            return flow.step1_get_authorize_url()

    print 'Credentials ->', credentials

    http = httplib2.Http()
    http = credentials.authorize(http)
    self.service = build('youtube', 'v3', http=http)
    return None

AUTH_JSON は、API アカウントをセットアップしたときにダウンロードしたものです。Storage は、postgres db で動作するようにカスタマイズされたバージョンのストレージですが、原則は同じです。

于 2013-03-27T05:09:11.660 に答える