向Square Connect api请求列出付款
本文关键字:付款 请求 api Square Connect | 更新日期: 2023-09-27 18:00:31
我正试图向Square Connect api请求列出付款。我收到这个错误
"远程服务器返回错误:(401)未经授权。"
api说打开您喜欢的命令行应用程序(如使用Mac的终端),运行以下curl命令,在指定的位置提供访问令牌:curl-H"授权:承载人个人_ACCESS_TOKEN"https://connect.squareup.com/v1/me/payments
这是我的密码。我做错了什么?
WebRequest request = WebRequest.Create("https://connect.squareup.com/v1/me/payments");
request.ContentType = "application/json";
request.Method = "GET";
request.Headers("Authorization") = "XXXXX";
HttpWebResponse response = null;
string responseMessage = null;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK) {
using (Stream stream = response.GetResponseStream()) {
using (StreamReader reader = new StreamReader(stream)) {
responseMessage = reader.ReadToEnd();
}
}
}
Assert.IsNotNull(responseMessage);
var client = new RestSharp.RestClient();
var request = new RestRequest("https://connect.squareup.com/v1/me/payments", Method.GET);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Authorization", "Bearer xxxxx");
//setHeaders(request);
var Response = client.Execute(request);
而不是
request.Headers("Authorization")="XXXXX";
做这个
request.Headers.Add(HttpRequestHeader.Authorization,"Bearer"+yourPersonalAccessToken);