TypeScriptでXHR-Request経由でOAuth2トークンにアクセスしようとしました。XHRにGrant_Typeを入れる場所
私は、iOSエミュレータで実行されているNativeScriptアプリケーション(TypeScriptテンプレート内)を使用して呼び出しを行っています。
マイコード:
var oReq = new XMLHttpRequest();
oReq.open("POST", "https://api.sandbox.paypal.com/v1/oauth2/token", true);
// oReq.withCredentials = true;
// oReq.setRequestHeader('grant_type', "client_credentials");
// where client_credentials = clientID:secret
oReq.setRequestHeader('Authorization', "Basic " + this.authorizationBasic);
//where AutorizationBasic is the base64 String of my credentials
oReq.setRequestHeader('Accept', "application/json");
oReq.setRequestHeader('Accept-Language', "en_US");
oReq.onreadystatechange = function() {
console.log("state changed - new state: " + oReq.readyState + " and Status: " + oReq.status);
if (oReq.readyState === 4) {
if (oReq.status === 200) {
console.log(oReq.responseText);
} else {
console.log("Error: " + oReq.status + " Message: " + oReq.responseText);
}
}
};
console.log("Status: " + oReq.status);
oReq.send();
いくつかの研究を行った後、私はいくつか他の人がペイパルAPI(例えばhere)と同じ問題を持っていたこと、が分かりました。誰かがその問題を解決しましたか?それはおそらく間違っている私のコードですか?上のコードでは、私が試した他のいくつかのコメントしたものは何も動作していないようです。
API: https://developer.paypal.com/docs/integration/direct/make-your-first-call/
私は、これは、単純なコールにあまりにも長い間そのAPIを取っているので、かなり必死にしようとしています。私は私のために働いた私のclientID +の秘密でカールコマンドを試しました。誰が何をすべきか考えていますか? XHRを使用するより簡単な方法はありますか?