How to use the oauth2client.tools.argparser function in oauth2client

To help you get started, we’ve selected a few oauth2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github schlosser / eventum / eventum / authorize.py View on Github external
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run_flow
from oauth2client import tools

if len(sys.argv) < 3:
    msg = "eventum/authorize.py  "
    sys.exit(msg)
else:
    client_secret_path = sys.argv[1]
    client_credentials_path = sys.argv[2]
    sys.argv.remove(client_secret_path)
    sys.argv.remove(client_credentials_path)

    parser = argparse.ArgumentParser(parents=[tools.argparser])

    FLAGS = parser.parse_args()
    SCOPE = 'https://www.googleapis.com/auth/calendar'

    FLOW = flow_from_clientsecrets(
        client_secret_path,
        scope=SCOPE)

    # Save the credentials file here for use by the app
    storage = Storage(client_credentials_path)
    run_flow(FLOW, storage, FLAGS)
github youtube / api-samples / python / comment_handling.py View on Github external
# Call the API's comments.delete method to delete an existing comment.
def delete_comment(youtube, comment):
  youtube.comments().delete(
    id=comment["id"]
  ).execute()

  print "%s deleted succesfully" % (comment["id"])


if __name__ == "__main__":
  # The "videoid" option specifies the YouTube video ID that uniquely
  # identifies the video for which the comment will be inserted.
  argparser.add_argument("--videoid",
    help="Required; ID for video for which the comment will be inserted.")
  # The "text" option specifies the text that will be used as comment.
  argparser.add_argument("--text", help="Required; text that will be used as comment.")
  args = argparser.parse_args()

  if not args.videoid:
    exit("Please specify videoid using the --videoid= parameter.")
  if not args.text:
    exit("Please specify text using the --text= parameter.")

  youtube = get_authenticated_service(args)
  # All the available methods are used in sequence just for the sake of an example.
  try:
    video_comment_threads = get_comment_threads(youtube, args.videoid)
    parent_id = video_comment_threads[0]["id"]
    insert_comment(youtube, parent_id, args.text)
    video_comments = get_comments(youtube, parent_id)
    update_comment(youtube, video_comments[0])
    set_moderation_status(youtube, video_comments[0])
github GoogleCloudPlatform / cloud-storage-docs-json-api-examples / python-example / compose-sample.py View on Github external
from oauth2client import file
from oauth2client import client
from oauth2client import tools

# Define sample variables.
_BUCKET_NAME = 'example-bucket'
_FILE1_NAME = 'test1.txt'
_FILE2_NAME = 'test2.txt'
_COMPOSITE_FILE_NAME = 'test-composite.txt'
_API_VERSION = 'v1'

# Parser for command-line arguments.
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])


# CLIENT_SECRETS is name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret. You can see the Client ID
# and Client secret on the APIs page in the Cloud Console:
# 
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

# Set up a Flow object to be used for authentication.
# Add one or more of the following scopes. PLEASE ONLY ADD THE SCOPES YOU
# NEED. For more information on using scopes please see
# .
FLOW = client.flow_from_clientsecrets(CLIENT_SECRETS,
  scope=[
      'https://www.googleapis.com/auth/devstorage.full_control',
      'https://www.googleapis.com/auth/devstorage.read_only',
github GoogleCloudPlatform / cloud-storage-docs-json-api-examples / python-example / storage-sample.py View on Github external
import json

from apiclient import discovery
from oauth2client import file
from oauth2client import client
from oauth2client import tools

# Define sample variables.
_BUCKET_NAME = '[[INSERT_YOUR_BUCKET_NAME_HERE]]'
_API_VERSION = 'v1'

# Parser for command-line arguments.
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])


# CLIENT_SECRETS is name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret. You can see the Client ID
# and Client secret on the APIs page in the Cloud Console:
# 
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

# Set up a Flow object to be used for authentication.
# Add one or more of the following scopes. PLEASE ONLY ADD THE SCOPES YOU
# NEED. For more information on using scopes please see
# .
FLOW = client.flow_from_clientsecrets(CLIENT_SECRETS,
  scope=[
      'https://www.googleapis.com/auth/devstorage.full_control',
      'https://www.googleapis.com/auth/devstorage.read_only',
github GoogleCloudPlatform / gce-oreilly / ch7-7.py View on Github external
import argparse
import httplib2
import os
import sys

from apiclient import discovery
from oauth2client import file
from oauth2client import client
from oauth2client import tools

# Parser for command-line arguments.
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])

# CLIENT_SECRET is the name of a file containing the OAuth 2.0 information
# for this application, including client_id and client_secret.
CLIENT_SECRET = os.path.join(os.path.dirname(__file__), 'client_secret.json')

# Set up a Flow object to be used for authentication. PLEASE ONLY
# ADD THE SCOPES YOU NEED. For more information on using scopes please
# see .
FLOW = client.flow_from_clientsecrets(
    CLIENT_SECRET,
    scope=['https://www.googleapis.com/auth/compute'],
    message=tools.message_if_missing(CLIENT_SECRET))

def main(argv):
  # Parse the command-line flags.
  flags = parser.parse_args(argv[1:])
github Freeseer / freeseer / src / freeseer / frontend / cli.py View on Github external
def setup_parser_config_youtube(subparsers):
    """Setup Youtube config parser"""
    from oauth2client import tools
    # Inherent Google API argparser
    parser = subparsers.add_parser("youtube", help="Obtain OAuth2 token for Youtube access", parents=[tools.argparser])
    defaults = youtube.get_defaults()
    parser.add_argument("-c", "--client-secrets", help="Path to client secrets file", default=defaults["client_secrets"])
    parser.add_argument("-t", "--token", help="Location to save token file", default=defaults["oauth2_token"])
github Yeraze / CalendarHangout / hangoutFix.py View on Github external
from dateutil.parser import *
from dateutil.tz import *

from apiclient import discovery
from oauth2client import file
from oauth2client import client
from oauth2client import tools

CalendarID = "FILL IN HERE"

# Parser for command-line arguments.
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])


# CLIENT_SECRETS is name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret. You can see the Client ID
# and Client secret on the APIs page in the Cloud Console:
# 
CLIENT_SECRETS = os.path.expanduser('~/.hangoutFix/client_secrets.json')

# Set up a Flow object to be used for authentication.
# Add one or more of the following scopes. PLEASE ONLY ADD THE SCOPES YOU
# NEED. For more information on using scopes please see
# .
FLOW = client.flow_from_clientsecrets(CLIENT_SECRETS,
                                      scope=[
                                      'https://www.googleapis.com/auth/calendar',
                                      'https://www.googleapis.com/auth/calendar.readonly',
github grow / grow / grow / common / oauth.py View on Github external
def get_or_create_credentials(scope, storage_key=DEFAULT_STORAGE_KEY):
    key_file = os.getenv('AUTH_KEY_FILE')
    # If AUTH_KEY_FILE is unset, use default auth key file if it exists.
    if not key_file and os.path.exists(DEFAULT_AUTH_KEY_FILE):
        key_file = DEFAULT_AUTH_KEY_FILE
    if key_file:
        key_file = os.path.expanduser(key_file)
        return (service_account.
            ServiceAccountCredentials.from_json_keyfile_name(key_file, scope))
    if appengine and utils.is_appengine():
        return appengine.AppAssertionCredentials(scope)
    credentials, storage = get_credentials_and_storage(scope,
        storage_key=storage_key)
    if credentials is None:
        parser = tools.argparser
        if os.getenv('INTERACTIVE_AUTH'):
            args = []
        else:
            args = ['--noauth_local_webserver']
        flags, _ = parser.parse_known_args(args)
        flow = client.OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, scope,
                                          redirect_uri=REDIRECT_URI)
        credentials = tools.run_flow(flow, storage, flags)
        # run_flow changes the logging level, so change it back.
        logging.getLogger().setLevel(getattr(logging, 'INFO'))
    # Avoid logspam by logging the email address only once.
    if hasattr(credentials, 'id_token') and credentials.id_token:
        email = credentials.id_token.get('email')
        global _LAST_LOGGED_EMAIL
        if email and _LAST_LOGGED_EMAIL != email:
            logging.info('Authorizing using -> {}'.format(email))
github GoogleCloudPlatform / kafka-pubsub-emulator / demo / python-rest-client / main.py View on Github external
API_SERVICE_NAME = 'pubsub'
API_VERSION = 'v1'
CLIENT_SECRETS = 'client_secret.json'
CREDENTIAL_FILE = '.credential.dat'
SCOPES = ('https://www.googleapis.com/auth/cloud-platform',
          'https://www.googleapis.com/auth/pubsub')
TOPIC_FORMAT = 'projects/{project}/topics/{topic}'
SUBSCRIPTION_FORMAT = 'projects/{project}/subscriptions/{sub}'

# Map standard API object keys to underscore_cased keys used by the gRPC gateway
MESSAGE_IDS = 'messageIds'
RECEIVED_MESSAGES = 'receivedMessages'
ACK_ID = 'ackId'

parser = argparse.ArgumentParser(
    description='Demo program with Pub/Sub', parents=[tools.argparser])
parser.add_argument(
    'action', choices=('publish', 'subscribe'), help='Publish or Subscribe')
parser.add_argument('project', help='GCP Project Id')
parser.add_argument('--gateway', help='Hostname and port of Emulator gateway')
parser.add_argument('--topic', help='Topic to Publish to')
parser.add_argument('--subscription', help='Subscription to Pull from')

logger = logging.getLogger('pubsub_demo')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s [%(levelname)s]: %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
github GoogleCloudPlatform / gce-oreilly / ch3-1.py View on Github external
import argparse
import httplib2
import os
import sys

from apiclient import discovery
from oauth2client import file
from oauth2client import client
from oauth2client import tools

# Parser for command-line arguments.
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])

# CLIENT_SECRET is the name of a file containing the OAuth 2.0 information
# for this application, including client_id and client_secret.
CLIENT_SECRET = os.path.join(os.path.dirname(__file__), 'client_secret.json')

# Set up a Flow object to be used for authentication. PLEASE ONLY
# ADD THE SCOPES YOU NEED. For more information on using scopes
# see .
FLOW = client.flow_from_clientsecrets(
    CLIENT_SECRET,
    scope=['https://www.googleapis.com/auth/compute'],
    message=tools.message_if_missing(CLIENT_SECRET))

# JSON doc capturing details of persistent disk creation request. 
BODY1 = {
  "name": "new-disk",