当前位置: 首页>>代码示例>>Python>>正文


Python Credentials.put方法代码示例

本文整理汇总了Python中model.Credentials.put方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.put方法的具体用法?Python Credentials.put怎么用?Python Credentials.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Credentials的用法示例。


在下文中一共展示了Credentials.put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import put [as 别名]
  def get(self):
    """Handle code exchange."""
    code = self.request.get('code')
    if not code:
      # TODO: Display error.
      return None
    oauth_flow = self.create_oauth_flow()

    # Perform the exchange of the code. If there is a failure with exchanging
    # the code, return None.
    try:
      creds = oauth_flow.step2_exchange(code)
    except FlowExchangeError:
      # TODO: Display error.
      return None

    users_service = util.create_service('oauth2', 'v2', creds)
    # TODO: Check for errors.
    user = users_service.userinfo().get().execute()

    userid = user.get('id')
    username = user.get('name')
    # Store the credentials in the data store using the userid as the key.
    # TODO: Hash the userid the same way the userToken is.
    """StorageByKeyName(Credentials, userid, 'credentials').put(creds)"""
    entity = Credentials(name = username,
                        credentials = creds,
                        key_name = userid)
    entity.put()
    logging.info('Successfully stored credentials for user: %s', entity)
    util.store_userid(self, userid)

    self._perform_post_auth_tasks(userid, creds)
    self.redirect('/')
开发者ID:macyk,项目名称:BikeShare,代码行数:36,代码来源:handler.py


注:本文中的model.Credentials.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。