Youtube在android..returning无效凭据中添加订阅

时间:2013-09-25 05:00:26

标签: java android youtube

我在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"
  }
}

0 个答案:

没有答案