Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default state of noauth_local_webserver?

I'm currently making a GUI YouTube video uploader for my community, but since I don't want all of my users to get my client_id and client_secret, I encoded them. Problem is that whenever program runs (it's not being run from command line using parameters, it gets those informations from Tkinter GUI) it start to authenticate users via web link, which contains real client_id and client_secret. I tried to use --noauth_local_webserver parameter but without success, since nothing is being run from command-line (I haven't found way to run this parameter without command line). As I saw on official docs, this parameter is set to "False" by default, is there any way to change that, or is there any way to disable web authentication? This is my code which I use to authenticate and start uploading a video (it's pretty much default one from official docs, with few changes so it fits my needs):

def get_authenticated_service():
    makeitreal() #this is function which decodes encoded client_id and client_secret
    flow = flow_from_clientsecrets(os.path.abspath(os.path.join(os.path.dirname(__file__), "client_secrets.json")), scope=YOUTUBE_UPLOAD_SCOPE,
    message=MISSING_CLIENT_SECRETS_MESSAGE)
    storage = Storage("%s-oauth2.json" % sys.argv[0])
    credentials = storage.get()

    if credentials is None or credentials.invalid:
       credentials = run(flow, storage)

    return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
      http=credentials.authorize(httplib2.Http()))

def initialize_upload():
    makeitreal() #this is function which decodes encoded client_id and client_secret
    youtube = get_authenticated_service()
    os.remove(os.path.join(os.path.dirname(__file__), "upload_video.py-oauth2.json")) #I use this to remove this json since it's not being used anymore and it contains client_id and client_secret
   tags = None

   insert_request = youtube.videos().insert(
     part="snippet,status",
     body=dict(
       snippet=dict(
         title=video_title, #####
         description=video_desc, # These 3 parameters are not being gathered through command line as it was in default code, I changed it so it gets these from Tkinter GUI
         tags=video_keywords, ####
         categoryId="22"
       ),
       status=dict(
         privacyStatus=VALID_PRIVACY_STATUSES[0]
       )
      ),
# chunksize=-1 means that the entire file will be uploaded in a single
# HTTP request. (If the upload fails, it will still be retried where it
# left off.) This is usually a best practice, but if you're using Python
# older than 2.6 or if you're running on App Engine, you should set the
# chunksize to something like 1024 * 1024 (1 megabyte).
      media_body=MediaFileUpload(filename, chunksize=-1, resumable=True)
   )
   makeitfake() #this is function which encodes previously decoded client_id and client_secret
   resumable_upload(insert_request) #this function uploads video

Thanks in advance, Amar!

like image 393
Amar Kalabić Avatar asked Oct 05 '14 14:10

Amar Kalabić


1 Answers

You're missing some code. Update to the latest API and examples and it's as simple as: args.noauth_local_webserver = True

Anyway, here's some of the code if you want to try adding support for argparser yourself. There's no longer a run but a run_flow. But you can pass args as the third parameter to your existing run function.

from oauth2client.tools import argparser, run_flow
args = argparser.parse_args()
args.noauth_local_webserver = True
credentials = run_flow(flow, storage, args)

Alternatively, if you must make it work, you can modify oauth2client/tools.py and search for if not flags.noauth_local_webserver and right above that just add flags.noauth_local_webserver = True However, I must point out that modifying core packages is not recommended as your changes will be clobbered the next time you update your packages. The cleanest solution is to update to the latest versions of everything which makes it easier to do what you want to do.

like image 190
jaggedsoft Avatar answered Sep 21 '22 23:09

jaggedsoft