Cant import Request, Session and response Facebook SDK 4.0. [Egregious Documentation]

一曲冷凌霜 提交于 2019-12-08 09:40:16

问题


I am using the Facebook SDK 4.0 and I want to post on users wall using the OpenGraph API.

I have defined the Action as:

  • Celebrating

The object as

  • Milestone

Now when in the Facebook Dev console I click on get code and switch to Android I get the following snippet:

Request request = new Request(
    Session.getActiveSession(),
    "me/objects/friendsampleapp:milestone",
    params,
    HttpMethod.POST
);

Response response = request.executeAndWait();

Here I cant get options to import Response, Request and Session.

I get an option to import com.facebook.login.LoginClient.Request; but with a red squiggly line which on hover says: The type com.facebook.login.LoginClient is not visible.

The point worth to note here is that in the same activity, my login is working fine so this is not an issue with importing the Facebook Library.

In the Changelog Facebook mentions:

Session Removed - AccessToken, LoginManager and CallbackManager classes supercede and replace functionality in the Session class.

I wonder if Facebook expects me to dream of how to interface their API with my code when its all broken, releasing SDK's at this rate, is not helping anyone.

I also tried to log a bug report with Facebook but however seems for facebook, that is broken too!

Edit:

Digging deeper I have changed the above code to:

Bundle params = new Bundle();
                GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(),"me/objects/friendsampleapp:milestone",params, HttpMethod.POST);
                GraphResponse response = request.executeAndWait();


                Bundle params1 = new Bundle();
                params1.putString("milestone", "http://samples.ogp.me/812890225461181");

                GraphRequest request1 = new GraphRequest(
                        AccessToken.getCurrentAccessToken(),"me/friendsampleapp:celebrating",params,HttpMethod.POST);
                GraphResponse response1 = request.executeAndWait();

But however I am confused, what next?


回答1:


Here is the final thing I have come up with and apparently, it does work:

ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                        .putString("og:type", "friendsampleapp:milestone")
                        .putString("og:title", "A Game of Thrones")
                        .putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")

                        .build();


                // Create an action
                ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                        .setActionType("friendsampleapp:celebrating")
                        .putObject("milestone", object)
                        .build();


                // Create the content
                ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                        .setPreviewPropertyName("milestone")
                        .setAction(action)
                        .build();




                ShareDialog.show(getActivity(), content); 



回答2:


Because the facebook docs are terrible. In the upgrade guide they show how to make a request

GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject user, GraphResponse response) {
                if (user != null) {
                    profilePictureView.setProfileId(user.optString("id"));
                }
            }
    }).executeAsync();

https://developers.facebook.com/docs/android/upgrading-4.x



来源:https://stackoverflow.com/questions/29936840/cant-import-request-session-and-response-facebook-sdk-4-0-egregious-documenta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!