gpt4 book ai didi

java - 服务器返回 HTTP 响应代码 : 400 facebook

转载 作者:太空宇宙 更新时间:2023-11-04 11:36:56 25 4
gpt4 key购买 nike

我遇到一个问题:

ERROR : Server returned HTTP response code: 400 for URL

URL: https://graph.facebook.com/me?fields=id%2Cname%2Cemail%2Cgender& access_token=XXXXXXXXXXXXXXXXXXX

下面是我的代码:

public String getFBGraph() {
String graph = null;

try {

String g ="https://graph.facebook.com/me?fields=id%2Cname%2Cemail%2Cgender&"+accessToken;


URL u=new URL(g);
URLConnection c=u.openConnection();


BufferedReader in=new BufferedReader(new InputStreamReader(c.getInputStream()));
String inputLine;

StringBuffer b=new StringBuffer();
while ((inputLine=in.readLine())!=null)
b.append(inputLine+"\n");
in.close();
graph=b.toString();
//System.out.println(graph);
} catch (Exception e) {
e.printStackTrace();

throw new RuntimeException("ERROR in getting FB graph data. "+e);
}
return graph;

}

当我从调用方法运行它时,当我将相同的网址复制粘贴到浏览器获取输出时,我收到错误,请帮助我,我的 accesstoken 是完美的,问题是什么?

最佳答案

很可能您只是忘记将 access_token= 参数名称添加到 URL 字符串中:

字符串 g ="https://graph.facebook.com/me?fields=id%2Cname%2Cemail%2Cgender&"+accessToken

Facebook 将使用 HTTP 状态代码 400 进行响应,在本例中:

10.4.1 400 Bad Request The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

并且会说一些类似的话

"An active access token must be used to query information about the current user."

在响应正文中。

关于java - 服务器返回 HTTP 响应代码 : 400 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43182408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com