无法以编程方式更新扩展程序

时间:2017-03-11 20:56:55

标签: python google-chrome-extension google-api

信息闪烁from here

鉴于我有ACCESS_TOKENAPP_ID,我应该可以使用以下内容更新Chrome扩展程序。

r = requests.put(
   'https://www.googleapis.com/upload/chromewebstore/v1.1/items/%s' % APP_ID,
   headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
            'x-goog-api-version': "2"},
   files={'file': open('target_extension.crx', 'rb')})
print r.text

打印:

{"error":{"errors":[{"domain":"global","reason":"notUpload","message":"Not an upload request. Re-send request to: https://www.googleapis.com/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}],"code":400,"message":"Not an upload request. Re-send request to: https://www.googleapis.com/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}}

好的,似乎很清楚,我切换了网址:

r = requests.put(
    'https://www.googleapis.com/chromewebstore/v1.1/items/%s' % APP_ID,
    headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
             'x-goog-api-version': "2"},
    files={'file': open('target_extension.crx', 'rb')})
print r.text

打印:

{"error":{"errors":[{"domain":"global","reason":"wrongUrlForUpload","message":"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}],"code":400,"message":"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}}

所以有人说我不是上传,转换。而另一个说我是上传,切换回来。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

Whelp,感谢wOxxOm的评论,我能够弄清楚这一点。另外,原来我应该上传zip,而不是crx

filepath = 'target_extension.zip'
with open(filepath, 'rb') as fh:
    resp = requests.put(
       'https://www.googleapis.com/upload/chromewebstore/v1.1/items/%s' % APP_ID,
       data=fh.read(),
       headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
                                 'x-goog-api-version': "2"},
       params={'file': filepath})