gae/golang で外部API呼び出しするには、appengine/urlfetchを使う。

http://code.google.com/intl/ja/appengine/docs/go/urlfetch/reference.html

gae/golangで、twitter apiを呼び出すコードを作って、開発環境では問題なかったので、デプロイしたら、外部API呼び出しで、下のメッセージが出た。

Get http://api.twitter.com/1/trends/1118370.json: operation not permitted

いろいろ試した結果、本家ドキュメントに書いてあった方法を使ったらできた。(最初からドキュメントよむべき。とはいえ、pythonの時とかは、そんな心配せずに外部アクセスできた(と思う)んだから、もうちょっと目立つところに書いといて欲しかったと思った)

http://code.google.com/intl/ja/appengine/docs/go/urlfetch/overview.html

App Engine applications can communicate with other applications or access other resources on the web by fetching URLs. An app can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses. The URL Fetch service uses Google’s network infrastructure for efficiency and scaling purposes.

        //client := &http.Client{}
        client := urlfetch.Client(c)

修正したことは、httpclientを作るときに、appengine/urlfetch から取得するように変更しただけでした。

1件のコメント

  • Thanks alot – your answer solved all my problems after seevral days struggling

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


The reCAPTCHA verification period has expired. Please reload the page.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください