gpt4 book ai didi

android - 执行 RunKeeper 的获取请求

转载 作者:搜寻专家 更新时间:2023-11-01 09:07:00 25 4
gpt4 key购买 nike

我正在尝试向 RunKeeper API 发出此请求:

GET /user HTTP/1.1
Host: api.runkeeper.com
Authorization: Bearer xxxxxxxxxxxxxxxx
Accept: application/vnd.com.runkeeper.User+json

我的代码:

private static final String BASEURL = "http://api.runkeeper.com";  

public HttpResponse getUserInformation() throws IOException {
DefaultHttpClient client = new DefaultHttpClient();
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF_8");
HttpProtocolParams.setUseExpectContinue(params, false);

client.setParams(params);
HttpGet get = new HttpGet(BASEURL.concat("/user"));
String credentials = getCredentials();
get.addHeader("Authorization", "Basic " + credentials);
get.addHeader("Accept", "application/vnd.com.runkeeper.User+json");
return client.execute(get);
}

private String getCredentials() {
String source = "Authorization" + ":" + "Bearer " + getAccessToken();
String ret = Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP);
return ret;
}

但我不断得到:

HTTP Status 500 - The server encountered an internal error () that prevented it from fulfilling this request.

我这里的错误是什么?

最佳答案

您使用的 URL 不正确。您应该只请求 /user

用这个添加一个接受头:

get.addHeader("Accept", "application/vnd.com.runkeeper.User+json");

您确定您添加的凭据信息正确吗?文档指出授权 header 应类似于 Bearer xxxxxxxxxxxxxxxxxxx,而您的是 Basic ...。无需进一步研究,也许这可能是解决方案:

get.addHeader("Authorization", "Bearer " + getAccessToken());

如果仍然不能正常工作,this页面指​​出,如果您收到内部服务器错误,您应该联系他们来解决问题。我想这可以在 this Google Group 中完成.

关于android - 执行 RunKeeper 的获取请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11115091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com