繁体   English   中英

Android上的Facebook Graph API搜索

[英]Facebook Graph API Searching on Android

我使用以下代码来从Facebook Graph API检索数据,并且可以正常工作。

GraphRequest.newGraphPathRequest(AccessToken.getCurrentAccessToken()
                        , "/me"
                        , new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse response) {
                                showToast(response.toString());
                                ((TextView) findViewById(R.id.result_textview)).setText(response.toString());
                            }
                        }).executeAsync();

但是,当我使用以下可在Graph API Explorer中运行的搜索查询时,它将不再起作用。

GraphRequest.newGraphPathRequest(AccessToken.getCurrentAccessToken()
                        , "/search?q=coffee&type=place"
                        , new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse response) {
                                showToast(response.toString());
                                ((TextView) findViewById(R.id.result_textview)).setText(response.toString());
                            }
                        }).executeAsync();

错误json在下面。

Response:responseCode:400,
graphObject:null,
error:{  
   HttpStatus:400,
   errorCode:100,
   errorType:GraphMethodException,
   errorMessage:   Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
}
}

请阅读文档。 您做错了方法。

new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "...?fields={fieldname_of_type_Location}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync()

要么

GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/search",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("type", "place");
parameters.putString("center", "53,27");
parameters.putString("distance", "30000");
request.setParameters(parameters);
request.executeAsync();

在现场,您可以使用国家/地区,经度,纬度,引用等。这是文档

希望这对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM