How to login to a site using OAuth, python? -
so have script needs access features of website requires login via oauth.
i have oauth client secrets file dev console- right script can retrieve list of user's youtube videos- have now
__author__ = 'anish' import httplib2 import sys googleapiclient.discovery import build oauth2client.client import flow_from_clientsecrets oauth2client.file import storage oauth2client.tools import argparser, run_flow import requests requests_oauthlib import oauth1session # of code sourced https://developers.google.com/youtube/v3/guides/uploading_a_video client_secrets_file = "client_secrets.json" youtube_read_write_scope = "https://www.googleapis.com/auth/youtube" youtube_api_service_name = "youtube" youtube_api_version = "v3" missing_client_secrets_message = "missing client secrets" def get_credentials(args): flow = flow_from_clientsecrets(client_secrets_file, scope=youtube_read_write_scope) storage = storage("%s-oauth2.json" % sys.argv[0]) credentials = storage.get() if credentials none or credentials.invalid: credentials = run_flow(flow, storage, args) return credentials def videos(youtube, uid): initial = youtube.playlistitems().list(part="snippet", maxresults=50, playlistid="uuy2lh8b-y0r-35llcjoppzw").execute() yield initial while "nextpagetoken" in initial: initial = youtube.playlistitems().list(part="snippet", maxresults=50, playlistid="uuy2lh8b-y0r-35llcjoppzw", pagetoken=initial["nextpagetoken"]).execute() yield initial if __name__ == "__main__": video_list = [] http = get_credentials(argparser.parse_args()).authorize(httplib2.http()) rq = http.request("http://github.com", method="get") print(rq[1]) youtube = build(youtube_api_service_name, youtube_api_version, http=http) info = youtube.channels().list(part="contentdetails", forusername="indianarobotics").execute() uploads_id = info["items"][0]["contentdetails"]["relatedplaylists"]["uploads"] v in videos(youtube, uploads_id): item in v["items"]: video_list.append([item["snippet"]["title"], item["snippet"]["resourceid"]["videoid"]]) v_info in video_list: print(v_info)
so access token google api's works. however, when things like
print(http.request("http://github.com", method="get")
i login page response, though use oauth sign github , credentials have account.
is there way use http
object have login site github? need to without sort of api site because website i'd interact with, thebluealliance doesn't have api oauth
Comments
Post a Comment