2014-01-10 96 views
1

我想讓我的訪問令牌的貝寶。獲取我的PayPal訪問請求AccessToken

我的下一個參數:EndPointClient Idsecretapi usernameapi signatureapi passwordapplication Id

我需要一個paypal客戶端才能做到嗎?

我跟着這個鏈接:https://developer.paypal.com/docs/integration/direct/make-your-first-call/

,並試圖:

private string getAccessToken() { 
    var ppClient; // = new paypalClient(); // create a paypal client 

    Dictionary<string, object> parameters = new Dictionary<string, object>(); 

    parameters.Add("Accept", "application/json"); 
    parameters.Add("Accept-Language", "en_US"); 
    parameters.Add("grant_type", "client_credentials"); 

    var result = ppClient.Get("https://api.sandbox.paypal.com/v1/oauth2/token", parameters); 

    string accessToken = result["access_token"]; 
    return accessToken; 
} 

謝謝大家!

+0

那麼,什麼是錯誤您收到? – mituw16

+0

@ mituw16,ppClient應該初始化.. –

+0

在上面的代碼中,你註釋了初始化ppClient對象的部分。 – mituw16

回答

1

我會建議使用RestSharp(只搶NuGet包): -

 if (ServicePointManager.SecurityProtocol != SecurityProtocolType.Tls12) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // forced to modern day SSL protocols 
     var client = new RestClient(payPalUrl) { Encoding = Encoding.UTF8 }; 
     var authRequest = new RestRequest("oauth2/token", Method.POST) {RequestFormat = DataFormat.Json}; 
     client.Authenticator = new HttpBasicAuthenticator(clientId, secret); 
     authRequest.AddParameter("grant_type","client_credentials"); 
     var authResponse = client.Execute(authRequest); 
相關問題