Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google oAuth在云计算中的作用_Python_Google Cloud Platform_Google Cloud Functions - Fatal编程技术网

Python Google oAuth在云计算中的作用

Python Google oAuth在云计算中的作用,python,google-cloud-platform,google-cloud-functions,Python,Google Cloud Platform,Google Cloud Functions,我创建了一些与gmail一起使用的应用程序。但是我使用文档和gmail中的授权代码,为了完成它,我需要在浏览器中打开一个链接来完成身份验证,但是我如何在云功能中做到这一点,原则上这是不可能的 """Shows basic usage of the Gmail API. Lists the user's Gmail labels. """ creds = None # The file token.pick

我创建了一些与gmail一起使用的应用程序。但是我使用文档和gmail中的授权代码,为了完成它,我需要在浏览器中打开一个链接来完成身份验证,但是我如何在云功能中做到这一点,原则上这是不可能的

"""Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'gmail-sms-e30e484e728e.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('gmail', 'v1', credentials=creds)
    request = {
        'labelIds': ['INBOX'],
        'topicName': 'projects/sms-service-1606905645083/topics/sms'
    }
    results = service.users().messages().list(userId=user_id).execute()
    messages = results.get('messages', [])
    last_message_id = messages[0].get('id')
    notification_txt = show_chatty_threads(service, last_message_id)
    plivo_send_message(notification_txt)
我需要在浏览器中打开一个链接以完成 身份验证,但我如何在云功能中执行此操作 原则上是不可能的吗

"""Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'gmail-sms-e30e484e728e.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('gmail', 'v1', credentials=creds)
    request = {
        'labelIds': ['INBOX'],
        'topicName': 'projects/sms-service-1606905645083/topics/sms'
    }
    results = service.users().messages().list(userId=user_id).execute()
    messages = results.get('messages', [])
    last_message_id = messages[0].get('id')
    notification_txt = show_chatty_threads(service, last_message_id)
    plivo_send_message(notification_txt)
您不能在云函数中执行此操作。谷歌要求用户与网络浏览器交互以授权其帐户

对于云功能之类的服务,您要么需要传递给您的凭据(访问或身份令牌),要么需要使用服务帐户