2017-02-17 14 views
0

私はPayPalの支払いをプロジェクトに組み込もうとしていますが、現時点では失敗しています。PayPal API - (401)アクセストークンをリクエストするときに不正になる

基本的に、最初のステップは、WebRequestで行うことを試みているアクセストークンの要求と応答を取得することですが、私は401を吐き出します。

次の手順:ここhttps://developer.paypal.com/docs/integration/direct/make-your-first-call/

コードです:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
WebRequest request = WebRequest.Create("https://api.sandbox.paypal.com/v1/oauth2/token"); 
request.ContentType = "application/x-www-form-urlencoded"; 
request.Method = "POST"; 
request.Credentials = new NetworkCredential("client_id", "secret"); 
request.PreAuthenticate = true; 

string body = "grant_type=client_credentials"; 
byte[] buffer = Encoding.UTF8.GetBytes(body); 
request.ContentLength = buffer.LongLength; 

var reqStr = request.GetRequestStream(); 
reqStr.Write(buffer, 0, buffer.Length); 
reqStr.Close(); 

WebResponse response = request.GetResponse(); 

勿論、秘密コード:)

はありがとうございにおける実際の値に置き換えられるCLIENT_IDあなたの助け!

答えて

0

はそれを考え出したのおかげ:C# HttpWebRequest using Basic authentication

はPayPalで意図したとおり、私は基本認証を使用していませんでしたが判明します。 申し訳ありません.D

誰かがこの点を知りたいと考えています。

関連する問題