![](/img/trans.png)
[英]Why am I getting code 400 response instead of error json object in tomcat 9 with spring 5?
[英]Why am I getting a 400 response code?
我試圖在使用Java(restfb)使用Facebook API方面結識一些。 我正在嘗試以下代碼。
public class FBJava {
private String API_Key = "xxxxxx";
private String API_Secret = "xxxxxxxx";
public String firstReq = "https://graph.facebook.com/oauth/authorize?client_id="+API_Key+"&" +
"redirect_uri=http://www.facebook.com/connect/login_success.html& scope=publish_stream,offline_access,create_event";
public String secondReq = "https://graph.facebook.com/oauth/access_token?client_id="+API_Key+"" +
"&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret="+API_Secret+"&code=";
public static void main(String[] args) throws IOException {
FBJava fb = new FBJava();
System.out.println(fb.firstReq);
URL request = new URL(fb.firstReq);
HttpURLConnection conn = (HttpURLConnection) request.openConnection();
conn.connect();
int code = conn.getResponseCode();
System.out.println(code);
}
}
當我在瀏覽器中手動運行firstReq字符串時,它會將我重定向到正確的頁面。 但是,當我檢查響應代碼時,我得到了400,這意味着它是一個錯誤的請求。 我想知道為什么當我嘗試通過程序運行它時會有不同的響應。 我知道我做錯了什么,但是想知道什么是錯誤以及為什么會發生? 在這方面的任何見識將不勝感激。
firstReq
網址中有錯誤。 它在“&范圍”之間包含一個空格字符。 試試這個(我剛剛刪除了空格):
public String firstReq = "https://graph.facebook.com/oauth/authorize?client_id="+API_Key+"&" +
"redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_stream,offline_access,create_event";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.