Monday 15 February 2010

How do I use an OAuth2 token with ANY version of the youtube python API -


I started to grab the token Oauth2 with some functions:

I tried: < / p>

  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 ()   

but I'm not sure how to properly GetFormUploadToken or UpdateVideoEntry call. Earlier I was just using a developer_key and it was working (using gdata.youtube.service.YouTubeService () ).

I also tried to use this for example, but it did not comment very well and the docs were not any better:

I just tried to change Construction (YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, http = credentials.authorize (httplib2.Http ()))

the

Construction (YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, ACCESS_TOKEN = current_access_token)

But it's just complaining that it does not know that is ACCESS_TOKEN .

This is how I am doing this

  def _yt_oauth_flow_hack (auto, secret_json_str, scope, redirect_uri = none): "" "version of a hacked: oauth2client.clientflow_from_clientsecrets" "client_type, = clientsecrets.loads (secret_json_str) if client_type client_info [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): '' 'authentication process begins and URL us We have to authorize this to be authorized to use the material that gives it, otherwise create the service and no one will go back, '' 'credentials = self._storage.get (), then there is no credibility the Print: - flow = self._yt_oauth_flow_hack (AUTH_JSON, self.scope) flow.redirect_uri = OOB_CALLBACK_URN 'stored credentials we need fresh authorization' return flow.step1_get_authorize_url () elif (credentials.invali d or credentials.token_expiry & lt ; = (Datetime.now () + timedelta (second = time.timezone))): print 'end of certification period - try going to refresh them' Try: http = httplib2.Http ( ) Credentials Refresh (HT) Print 'Success!' Except AccessTokenRefreshError: Unable to refresh print credentials - Request new people. Credit http = httplib2.Http () http = credentials.authorize (http), self.service; - Flow = self._yt_oauth_flow_hack (AUTH_JSON, self.scope) flow.redirect_uri = OOB_CALLBACK_URN return flow.step1_get_authorize_url () print '& gt credibility' = Weight ( 'youtube', 'v3', http = http) No   

What do I download when I set up my API account AUTH_JSON storage is a customized version of their storage to work with a postgres db, but the principle is still the same.

No comments:

Post a Comment