2

我正在一个 android 应用程序中工作,我在 youtube 订阅 API v3 上使用插入方法。但它总是显示无效凭据错误。我还测试了未过期的访问令牌。请帮助我实现插入订阅。我的代码片段是

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://www.googleapis.com/youtube/v3/subscriptions");
httppost.addHeader("Accept", "application/json");
httppost.addHeader("part", "snippet");
httppost.addHeader("Authorization", accessToken);
JSONObject channelObj = new JSONObject();
channelObj.put("channelId", channelID);
JSONObject resourceObj = new JSONObject();
resourceObj.put("resourceId", channelObj);
JSONObject snippetObj = new JSONObject();               

snippetObj.put("snippet", resourceObj); 


String message = snippetObj.toString();
httppost.setEntity(new StringEntity(message, "UTF8"));
httppost.setHeader("Content-type", "application/json");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseString = StreamUtils.convertToString(response.getEntity().getContent());

我收到以下回复:-

    error: {
  errors: [
    {
      "domain": "global",
      "reason": "authError",
      "message": "Invalid Credentials",
      "locationType": "header",
      "location": "Authorization",
    }
  ],
  "code": 401,
  "message": "Invalid Credentials"
  }
}
4

0 回答 0