2016-10-12 5 views
2

他の同様の名前の質問は私の問題を解決していません。HTTPエラー400不正リクエスト(他の同様の質問は私を助けてくれません)

なぜこのエラーが発生しますか?このサンプルコードをGoogleのgithubからコピーして貼り付けました。

import pprint 

from googleapiclient.discovery import build 

def main(): 
    # Build a service object for interacting with the API. Visit 
    # the Google APIs Console <http://code.google.com/apis/console> 
    # to get an API key for your own application. 
    service = build("customsearch", "v1", 
     developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0") 

    res = service.cse().list(
     q='lectures', 
     cx='017576662512468239146:omuauf_lfve', 
    ).execute() 
    pprint.pprint(res) 

if __name__ == '__main__': 
    main() 

Here is where I go the code from

私はこのエラーを取得しています:

Traceback (most recent call last): 
    File "testpython", line 17, in <module> 
    main() 
    File "testpython", line 12, in main 
    cx='017576662512468239146:omuauf_lfve', 
    File "/home/mddrill/.local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/mddrill/.local/lib/python2.7/site-packages/googleapiclient/http.py", line 838, in execute 
    raise HttpError(resp, content, uri=self.uri) 
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/customsearch/v1?q=lectures&alt=json&cx=017576662512468239146%3Aomuauf_lfve&key=AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0 returned "Bad Request"> 
+0

本当にあなたの鍵ですか? –

答えて

1

私はそのbad URLにアクセスしようとした理由は、 "keyExpired" されていることを述べていました。また、あなたはここに置かコードは、次のドキュメントが含まれています

は、独自のアプリケーションのためのAPIキーを取得 には、Google APIコンソールhttp://code.google.com/apis/consoleをご覧ください。

としてみてください。がんばろう!

関連する問題