2017-01-08 11 views
0

このスクリプトは動作しません。私はDEVELOPER_KEYをGoogle APIから作成したAPIキーで置き換えます。誰かが私を助けることができたら本当に感謝します。このページのスクリプトは、https://developers.google.com/youtube/v3/code_samples/python#search_by_keywordgoogle-api-python-clientがデベロッパーキーで動作しない

#!/usr/bin/python 

from apiclient.discovery import build 
from apiclient.errors import HttpError 
from oauth2client.tools import argparser 


# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps 
# tab of 
# https://cloud.google.com/console 
# Please ensure that you have enabled the YouTube Data API for your project. 
DEVELOPER_KEY = "REPLACE_ME" 
YOUTUBE_API_SERVICE_NAME = "youtube" 
YOUTUBE_API_VERSION = "v3" 

youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) 

次のエラーメッセージが表示されます。

Traceback (most recent call last): 
    File "hello.py", line 16, in <module> 
    youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) 
    File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 226, in build 
    credentials=credentials) 
    File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 358, in build_from_document 
    credentials = _auth.default_credentials() 
    File "/home/alican/.local/lib/python2.7/site-packages/googleapiclient/_auth.py", line 40, in default_credentials 
    return oauth2client.client.GoogleCredentials.get_application_default() 
    File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/client.py", line 1264, in get_application_default 
    return GoogleCredentials._get_implicit_credentials() 
    File "/home/alican/.local/lib/python2.7/site-packages/oauth2client/client.py", line 1254, in _get_implicit_credentials 
    raise ApplicationDefaultCredentialsError(ADC_HELP_MSG) 
oauth2client.client.ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information. 
+2

推奨ページにアクセスして読んだことがありますか?適切な環境変数を設定しましたか? – MattDMo

+0

はい、問題はGoogle APIにアクセスするためにOAuth 2.0を使用したくないということです。APIキーを使用したいだけです。このスクリプトは実際には数週間前にうまく機能していました。 – alicankargin

+0

これは今、あなたに感謝します。私は指示を誤解していることに気付きました。 – alicankargin

答えて

0

google-api-python-clientバージョン1.6を使用する場合は、次の操作を行います。 https://console.developers.google.com/apis/credentialsにアクセスしてください。資格の作成を選択し、サービスアカウントキーを選択し、App Engineのデフォルトサービスアカウントを選択し、JSONファイルをダウンロードしてプロジェクトフォルダに配置します。それを環境変数GOOGLE_APPLICATION_CREDENTIALSとして設定します。

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./google_application_credentials.json"

1

google-api-python-clientのバージョン1.6に問題があります。以前のバージョン(1.5.5)を使用して問題を解決する必要があります。

+0

これは私の問題を解決しました –

関連する問題