コード例 #1
0
  @Override
  protected void onPreExecute() {
    super.onPreExecute();

    if (requests.getCallbackHandler() == null) {
      // We want any callbacks to go to a handler on this thread unless a handler has already
      // been specified.
      requests.setCallbackHandler(new Handler());
    }
  }
コード例 #2
0
 @Override
 protected List<GraphResponse> doInBackground(Void... params) {
   try {
     if (connection == null) {
       return requests.executeAndWait();
     } else {
       return GraphRequest.executeConnectionAndWait(connection, requests);
     }
   } catch (Exception e) {
     exception = e;
     return null;
   }
 }
コード例 #3
0
  public void getFacebookData() {
    final ArrayList<String> strings = new ArrayList<>();
    GraphRequestBatch batch;
    batch =
        new GraphRequestBatch(
            GraphRequest.newMeRequest(
                access_token,
                new GraphRequest.GraphJSONObjectCallback() {
                  @Override
                  public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                    if (graphResponse.getError() != null) {
                      // handle error
                      System.out.println("ERROR");
                    } else {
                      System.out.println("Success");
                    }

                    try {
                      String jsonresult = String.valueOf(jsonObject);
                      System.out.println("JSON Result" + jsonresult);
                      String str_firstname = jsonObject.getString("name");
                      nameText.setText(str_firstname);
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }
                  }
                }),
            new GraphRequest(
                access_token,
                "me/feed",
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                  @Override
                  public void onCompleted(GraphResponse graphResponse) {
                    if (graphResponse.getError() != null) {
                      // handle error
                      System.out.println("ERROR");
                    } else {
                      System.out.println("Success");
                    }

                    try {
                      JSONObject json = null;
                      JSONArray jarray = null;
                      json = new JSONObject(graphResponse.getRawResponse());
                      jarray = json.getJSONArray("data");
                      for (int i = 0; i < jarray.length(); i++) {
                        JSONObject oneStory = null;
                        oneStory = jarray.getJSONObject(i);

                        String story;

                        story = oneStory.optString("story");
                        if (story.isEmpty()) story = oneStory.optString("message");
                        strings.add(i, story);
                      }
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }

                    Log.d("RESPONSE", strings.toString());
                    ArrayAdapter<String> arrayAdapter =
                        new ArrayAdapter<String>(
                            MainActivity.this, android.R.layout.simple_list_item_1, strings);
                    dataList.setAdapter(arrayAdapter);
                  }
                }));

    batch.executeAsync();
  }