3
我試圖讓使用的Java對象:Google+的OAuth無效頭
https://www.googleapis.com/oauth2/v1/userinfo?alt=json
我通過以前獲得我的訪問令牌Google+用戶的信息:
URL googleURL = new URL("https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
URLConnection googleConn = googleURL.openConnection();
googleConn.setAllowUserInteraction(false);
googleConn.setDoOutput(true);
**googleConn.setRequestProperty("Authorization", "Bearer "+accessToken);**
BufferedReader rd = new BufferedReader(new InputStreamReader(googleConn.getInputStream()));
String result = "";
while(rd.ready())
result += rd.readLine();
rd.close();
但它給我的HTTP錯誤代碼401(無效標題)。
這是在頭中傳遞訪問令牌的正確方法嗎?
googleConn.setRequestProperty("Authorization", "Bearer "+accessToken);