Get user info from YouTube Google API in Python (API v3)
|September 22, 2014||Posted by forumadmin under TechQns||
I’m new to the Google APIs but making some progress; I have a Django app that is getting a list of a user’s video uploads. This works great! I took everything from the docs and the examples Google offers.
I would like to be able to also get the user’s profile information that is connected with the YouTube account they are authorized under (because a user on my site may have more than one YouTube account and I need to tell them apart).
Here is a simplified version of what I have that is working:
YOUTUBE_READONLY_SCOPE = "https://www.googleapis.com/auth/youtube.readonly" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" # added this to increase the scope GOOGLE_USER_INFO_SCOPE = "https://www.googleapis.com/auth/userinfo.profile" FLOW = flow_from_clientsecrets( CLIENT_SECRETS, scope=[ YOUTUBE_READONLY_SCOPE, GOOGLE_USER_INFO_SCOPE ], redirect_uri='http://127.0.0.1:8000/youtube/oauth2callback') @login_required def index(request): storage = Storage(CredentialsModel, 'id', request.user, 'credential') credential = storage.get() http = httplib2.Http() http = credential.authorize(http) # gets a workable YouTube service! service = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, http=http) # how do I get the user name or email or other profile information here?
After reading this post I know I can’t just use
userinfo = build('userinfo', "v2", http=http) … but I’m a little confused as to what I do next. I read this example but it appears to be using a different library (I installed the
Do I need to install a different library (the
gdata library) in order to get user info? Or is the user info hidden in some other service I can call
build on (like the Google+ service)?
|Asked By – thornomad||Read Answers|