APIキーを使用しているので、私はAngularアプリケーションでGoogleのURL Shortenerを使用しています。使用しているサーバー側でgoogle apiコールを行う方がスマートで安全です角度。ノードリクエスト - そしてGoogle URLショートネクタ
見つかった$http
非常にまっすぐ進むが、ノードではすぐにわかった。npmパッケージrequest
を使うのが良いとすぐに分かった。
だから基本的に私は実行する必要があります。
POST https://www.googleapis.com/urlshortener/v1/url
Content-Type: application/json
{"longUrl": "http://www.google.com/"}
そして、私が現在書いている:
//Load the request module
var request = require('request');
//Configure and make the request
request({
url: 'https://www.googleapis.com/urlshortener/v1/url?key=XXXXXXXXX',
method: 'POST',
headers: { //We can define headers too
'Content-Type': 'application/json'
},
data: {
'longUrl': 'http://www.myverylongurl.com'
}
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, response.body);
}
});
を私はエラーを取得しておいてください。
"errors": [{ "domain": "global", "reason": "required", "message": "Required", "locationType": "parameter”, “location": "resource.longUrl"
}]
は私の要求を間違ってますか?
ありがとうございました。
質問は何ですか? – Cohars
質問を更新しました。ありがとう – userMod2
アクセストークンを取得していますか? cf [承認リクエスト](https://developers.google.com/url-shortener/v1/getting_started#OAuth2Authorizing) –