我正在使用 OkHttp 向 Bitbucket API 发出 POST 请求以创建新问题。他们的文档说私人回购或私人问题跟踪器需要身份验证才能使用此 API 创建新问题。我的回购和我的问题跟踪器都是公开的,所以不应该有任何问题。但是,当我拨打电话创建新问题时,我收到了 401 未经授权的响应。这是我用来拨打电话的代码:
FormEncodingBuilder builder = new FormEncodingBuilder();
String t = "{" +
"\"status\": \"new\"," +
"\"priority\": \"trivial\"," +
"\"title\": \"This is a title\"," +
"\"content\": \"This is the content\"," +
"\"is_spam\": false\n" +
"}";
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), t);
String url = "https://bitbucket.org/api/1.0/repositories/userName/repoName/issues"
Request request = new Request.Builder().url(url)
.post(requestBody)
.build();
Response response = new OkHttpClient().newCall(request).execute();
问题: 谁能告诉我为什么我会收到未经授权的回复?
更新
每吉姆雷德蒙德我已经更改了我的请求以首先进行身份验证。我现在正在向https://bitbucket.org/site/oauth2/authorize?client_id=myConsumerKey&response_type=token进行 POST并且我得到响应 200 OK 但我没有在标题中看到令牌...知道为什么我'我没有得到一个令牌作为回应?