1
votes

I have an app in facebook and I am trying to obtain long term token,

for that I call the following link:

https://graph.facebook.com/oauth/authorize?client_id=xxxxxx&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Faccesstokforfacebook%2Ffbaccess&scope=read_stream,read_insights,user_religion_politics,user_relationship_details,user_hometown,user_location,user_likes,user_activities,user_interests,user_education_history,user_work_history,user_website,user_groups,user_events,user_photos,user_videos,user_about_me,user_status,user_games_activity,user_tagged_places,user_actions.books,user_actions.video,user_actions.news

and the return url is a servlet with following codes:

response.setContentType("text/html");       
    PrintWriter out = response.getWriter();

    String accessCode = request.getParameter("code");
    System.out.println("dddd  "+accessCode);
    //print SUCCESS if code is found
    /*if (accessCode!=null){*/
        out.print("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\"><html><head><title>Facebook Access Granted</title></head><body>");
        out.print("<p>SUCCESS!</p><p>"+accessCode+"</p></body></html>");

and this servlet receives the very long code like this:

AQCY244eMOhxEVu3e6UEIl-qK974wTh-p0Il1ZdG9VEAYl5GdrjxxxxxxxxxxxxxxxxxxxxxxxxxxxxxQcJeUmeXFU56cbWbmXJdLQvEyIT7JWCxxu6tChkr9oCL1DVYxxv4v-j4Y_vaWGD7dYcxxxxxxxxxxxxxxxxxxTvZPHLU-tU5ySHrQrVgpo_i8minM73cyWxxxxxxxxxxxxxxdZvnrIhQXQ-B_3LAFzDcWe2NbCW7WSgmQ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMkJ55M0wHHbLmL4D-g_wLIwhpz4W_8Hz0h7v_ZL

Now when I use this token to get the all info for a page I get an error:

this is a link that I use:

https://graph.facebook.com/v2.0/khalatbari.hooman/feed?access_token=THE ABOVE CODE

and the error is:

enter image description here

Now I think the code that I get is not access token but I have no idea how to use this code to get access token!!!

can anyone help

1
Did you urlencode the access token before you used it in the url?WizKid
Yes and you can see it in the first link. even after using the first link a long code is returned but when I use it it says malform token though I am using exactly what facebook returnsHamed Minaee
Did you urlencode the access token before you added it to the second url? And the #= looks strange at the end of the access tokenWizKid
Thanks for your comment . Actually no I did not but after you said I did it with this website : url-encode-decode.com and the url did not change . Also the token that I posted above, is manipulated because of security reason but the real token ends with 0wHHbLmL4D-g_wLIwhpz4W_8Hz0h7v_ZL. Still I get the same errorHamed Minaee
If it doesn't work I would suggest filing a bug at developers.facebook.com/bugs and include the exact access token. You can mark the bug as confidential so no one else sees itWizKid

1 Answers

1
votes

Finally found solution for Facebook SDK 4.6.0 to getting limited comment's list for feed :

1> Calling commentInfo() firstly Inside Activity's oncreate() :

private boolean isLoadMoreCalled;

    commentInfo("", "true");

2> Putting load more method also there like:

        listViewCommentList.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                Log.d("scrollState", ""+scrollState);
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {


                int last_visible_in_screen = firstVisibleItem + visibleItemCount;

                if(last_visible_in_screen == totalItemCount && isLoadMoreCalled) {
                    Toast.makeText(getApplicationContext(), "Loading more Items 10", Toast.LENGTH_SHORT).show();
                    commentInfo(nextFeedUrl, "false");
                    isLoadMoreCalled  = false;
                }
            }
        });

3> create commentInfo() of outside onCreate() :

    public void commentInfo (String fields, final String isFirst) {

                /**     Festival Feed Comments Details @Facebook       */
                Bundle params = new Bundle();
                params.putString("fields", "message,created_time,from");
                params.putString("limit", "10");


                if(isFirst.equals("false")) {
                    params.putString("after", fields);
                }

                showProgressBar();
                /* make the API call */
                //refreshCurrentAccessTokenAsync();
                System.out.println("Acees Token Comment>>>"+ AccessToken.getCurrentAccessToken());

                new GraphRequest(AccessToken.getCurrentAccessToken(), "/"+ feedId +"/comments", params, HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response) {
                                /* handle the result */
                                System.out.println("Festival feed Comments response::" + String.valueOf(response.getJSONObject()));

                                try {
                                    JSONObject jObjResponse = new JSONObject(String.valueOf(response.getJSONObject()));

                                    JSONObject jObjPaging = jObjResponse.getJSONObject("paging");

                                    JSONObject jObjCursor = jObjPaging.getJSONObject("cursors");

                                    nextFeedUrl = "";
                                    nextFeedUrl = jObjCursor.getString("after");

                                    System.out.println("nextFeedUrl>>"+ nextFeedUrl);

                                        JSONArray jArrayData = jObjResponse.getJSONArray("data");
                                        for(int i = 0; i< jArrayData.length(); i++) {

Getting comments info & store into Data-Structure(Array-List)

    }

                                        if(isFirst.equals("true")) {
                                            fbFeedCommentAdapter = new FbFeedCommentAdapter();
                                            listViewCommentList.setAdapter(fbFeedCommentAdapter);
                                        }
                                        else {
                                            fbFeedCommentAdapter.notifyDataSetChanged();
                                        }

                                        if(!jObjPaging.has("next")) {
                                            isLoadMoreCalled = false;
                                        }
                                        else {
                                            isLoadMoreCalled = true;
                                        }

                                    dismissProgressBar();
                                }
                                catch (Exception e) {
                                    e.printStackTrace();
                                    dismissProgressBar();
                                }
                            }
                        }
                ).executeAsync();

            }

Here,

fbFeedCommentAdapter -> BaseAdapter

listViewCommentList -> Listview

Also refer How to use the Facebook Graph Api Cursor-based Pagination