我收到以下错误:“message”:“格式错误的访问令牌

时间:2014-08-03 18:54:06

标签: facebook facebook-graph-api

我在facebook上有一个应用程序,我正在尝试获取长期令牌,

为此我拨打以下链接:

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

,返回URL是一个包含以下代码的servlet:

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>");

并且这个servlet接收如下的非常长的代码:

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

现在,当我使用此令牌获取页面的所有信息时,我收到错误:

这是我使用的链接:

https://graph.facebook.com/v2.0/khalatbari.hooman/feed?access_token=THE上面的代码

,错误是:

enter image description here

现在我认为我得到的代码不是访问令牌,但我不知道如何使用此代码来获取访问令牌!!!

任何人都可以提供帮助

1 个答案:

答案 0 :(得分:2)

最终找到了 Facebook SDK 4.6.0 的解决方案,以获取 有限评论的供稿列表

<强> 1&GT;首先调用commentInfo()Inside Activity&#39; oncreate() :

private boolean isLoadMoreCalled;

    commentInfo("", "true");

<强> 2 - ;加载更多方法也就像:

        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&GT;创建外部onCreate()的commentInfo():

    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();

            }

下面,

fbFeedCommentAdapter - &gt; BaseAdapter

listViewCommentList - &gt; 的Listview

另请参阅How to use the Facebook Graph Api Cursor-based Pagination