簡體   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