Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Google app engine GAE应用程序可以在没有OAuth的情况下访问云存储RESTful API吗?_Google App Engine_Oauth_Google Cloud Storage_Google Api Python Client - Fatal编程技术网

Google app engine GAE应用程序可以在没有OAuth的情况下访问云存储RESTful API吗?

Google app engine GAE应用程序可以在没有OAuth的情况下访问云存储RESTful API吗?,google-app-engine,oauth,google-cloud-storage,google-api-python-client,Google App Engine,Oauth,Google Cloud Storage,Google Api Python Client,我们正在使用GAE云存储API来创建和访问文件。我们使用gsutil将我们的gae应用程序服务帐户添加到bucket的默认ACL中 下一步是做一些事情,比如列出bucket内容。因此,具有OAuth访问权限的RESTfulAPI似乎是一个可行的选择。但是,要从taskqueue访问云存储,我们希望避免OAuth舞蹈中的“用户同意”步骤。API控制台允许为此目的为服务帐户添加客户端id,但我们找不到任何使用服务帐户访问API的文档或示例 到目前为止,我们已经查看了应用程序(需要OAuth舞蹈)和示

我们正在使用GAE云存储API来创建和访问文件。我们使用gsutil将我们的gae应用程序服务帐户添加到bucket的默认ACL中

下一步是做一些事情,比如列出bucket内容。因此,具有OAuth访问权限的RESTfulAPI似乎是一个可行的选择。但是,要从taskqueue访问云存储,我们希望避免OAuth舞蹈中的“用户同意”步骤。API控制台允许为此目的为服务帐户添加客户端id,但我们找不到任何使用服务帐户访问API的文档或示例

到目前为止,我们已经查看了应用程序(需要OAuth舞蹈)和示例。这两个都不显示默认服务帐户的访问权限


有没有使用app engine服务帐户授权对云存储RESTful API的请求的示例?

我想您已经看到了这一点?


我没有使用这个API,但通过在数据存储中存储经过身份验证的OAuth令牌,在App Engine上使用了其他带有OAuth的API。类似的解决方案可能也适用于您

您可以使用互操作访问访问谷歌云存储,通过互操作访问,您可以使用访问密钥和密钥访问存储桶。

流程是,您可以在包中看到实现流程的示例代码(在中查找HmacAuthV1Handler)

使用RESTAPI而不进行OAuth舞蹈的最简单方法是使用GAE获取访问令牌,然后使用访问令牌访问Google云存储。在任何一种情况下,您都需要将应用程序标识的电子邮件表单添加到您的Google云存储项目中,如文档的先决条件部分所述(即使您没有使用文件API,您也需要这样做,因为这会设置您的项目,以便应用程序引擎应用程序可以访问它).

我正在发布一个小示例,它准确地说明了您的问题:如何使用App Engine服务帐户凭据访问Google云存储(特别是列出格式化的Google云存储桶)。如果可用,这将成为回购协议的一部分,但同时,代码如下:

import httplib2
import logging
import os
import pickle
import re

from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import AppAssertionCredentials

# Constants for the XSL stylesheet and the Google Cloud Storage URI.
XSL = '\n<?xml-stylesheet href="/listing.xsl" type="text/xsl"?>\n';
URI = 'http://commondatastorage.googleapis.com'

# Obtain service account credentials and authorize HTTP connection.
credentials = AppAssertionCredentials(
    scope='https://www.googleapis.com/auth/devstorage.read_write')
http = credentials.authorize(httplib2.Http(memcache))

class MainHandler(webapp.RequestHandler):

  def get(self):
    try:
      # Derive desired bucket name from path after domain name.
      bucket = self.request.path
      if bucket[-1] == '/':
        # Trim final slash, if necessary.
        bucket = bucket[:-1]
      # Send HTTP request to Google Cloud Storage to obtain bucket listing.
      resp, content = http.request(URI + bucket, "GET")
      if resp.status != 200:
        # If error getting bucket listing, raise exception.
        err = 'Error: ' + str(resp.status) + ', bucket: ' + bucket + \
              ', response: ' + str(content)
        raise Exception(err)
      # Edit returned bucket listing XML to insert style sheet for nice 
      # formatting and send results to client.
      content = re.sub('(<ListBucketResult)', XSL + '\\1', content)
      self.response.headers['Content-Type'] = 'text/xml'
      self.response.out.write(content)
    except Exception as e:
      self.response.set_status(404)
      self.response.out.write(str(e))

def main():
  application = webapp.WSGIApplication(
      [
       ('.*', MainHandler),
      ],
      debug=True)
  run_wsgi_app(application)

if __name__ == '__main__':
  main()
导入httplib2
导入日志记录
导入操作系统
进口泡菜
进口稀土
从google.appengine.api导入memcache
从google.appengine.ext导入webapp
从google.appengine.ext.webapp导入模板
从google.appengine.ext.webapp.util导入运行\u wsgi\u应用程序
从oauth2client.appengine导入AppAssertionCredentials
#XSL样式表和Google云存储URI的常量。
XSL='\n\n';
乌里http://commondatastorage.googleapis.com'
#获取服务帐户凭据并授权HTTP连接。
凭证=AppAssertionCredentials(
范围=https://www.googleapis.com/auth/devstorage.read_write')
http=凭证.authorize(httplib2.http(memcache))
类MainHandler(webapp.RequestHandler):
def get(自我):
尝试:
#从域名后的路径派生所需的bucket名称。
bucket=self.request.path
如果bucket[-1]=='/':
#如有必要,修剪最后一条斜线。
bucket=bucket[:-1]
#向Google云存储发送HTTP请求以获取bucket列表。
resp,content=http.request(URI+bucket,“GET”)
如果响应状态!=200:
#如果获取存储桶列表时出错,则引发异常。
err='Error:'+str(resp.status)+',bucket:'+bucket+\
“,答复:”+str(内容)
引发异常(错误)
#编辑返回的bucket列表XML以插入nice的样式表
#格式化并将结果发送到客户端。

content=re.sub(“(Google现在提供签名URL(查询字符串身份验证)访问云存储桶的模式。这允许服务帐户跳过OAuth舞蹈,并使用签名URL访问桶信息。请查看。

当App Engine已经有一个用于直接访问云存储的内置API时,为什么要使用restful API?内置API不允许我列出桶的内容。这是怎么回事在devserver上测试?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ama="http://doc.s3.amazonaws.com/2006-03-01">

<xsl:template match="/">
  <html>
  <body>
  <h2><a href="http://developer.google.com/storage">Google Cloud Storage</a> Con
tent Listing for Bucket 
      <xsl:value-of select="ama:ListBucketResult/ama:Name"/></h2>
    <table border="1" cellpadding="5">
      <tr bgcolor="#9acd32">
        <th>Object Name</th>
        <th>Modification Time</th>
        <th>ETag</th>
        <th>Size</th>
        <th>Storage Class</th>
      </tr>
      <xsl:for-each select="ama:ListBucketResult/ama:Contents">
      <tr>
        <td><xsl:value-of select="ama:Key"/></td>
        <td><xsl:value-of select="ama:LastModified"/></td>
        <td><xsl:value-of select="ama:ETag"/></td>
        <td><xsl:value-of select="ama:Size"/></td>
        <td><xsl:value-of select="ama:StorageClass"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>