【发布时间】:2016-10-05 02:33:01
【问题描述】:
我正在尝试通过 Xamarin Forms 使用 PayPal RESTful API,但在尝试获取 OAuth 令牌时遇到了麻烦。这是我正在运行的代码,在 Android 上发生错误。我在此处更改了身份验证标头,因此我的客户端 ID 和密码不公开。这是我基于此 HTTP 请求的 curl 命令:https://developer.paypal.com/docs/integration/direct/make-your-first-call/。谢谢。
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>();
【问题讨论】:
标签: c# paypal xamarin.forms httpclient