0
我嘗試通過Xamarin Forms使用PayPal RESTful API,並在嘗試獲取OAuth令牌時遇到麻煩。這是我正在運行的代碼,並且在Android上發生錯誤。我在這裏更改了身份驗證標頭,以便我的客戶端ID和密碼不可公開提供。這也是我基於這個HTTP請求的curl命令:https://developer.paypal.com/docs/integration/direct/make-your-first-call/。謝謝。當通過Httpclient提交HTTP請求時System.TypeLoadException
var getToken = new HttpClient(new NativeMessageHandler());
getToken.BaseAddress = new Uri("https://api.sandbox.paypal.com/v1/oauth2/token");
getToken.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
getToken.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en_US"));
getToken.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("**client_id**", "**secret**");
getToken.DefaultRequestHeaders.TryAddWithoutValidation("content-type", "application/x-www-form-urlencoded");
OAuthDetails clientCredentials = new OAuthDetails("client_credentials");
HttpResponseMessage tokenResponse = await getToken.PostAsJsonAsync("/v1/oauth2/token", clientCredentials);
AccessResponse accessInfo = await tokenResponse.Content.ReadAsAsync<AccessResponse>();