Question

I have took this code from internet, to post a message on facebook, from the android app :

this is the link : How can l post on facebook from android app with API wall without checking?

Request.Callback callback= new Request.Callback() {

  //some code
}

The problem is I don't know which Class should I import between :

_ DownloadManager

_ CORBA

_ sun.misc

Could you help me ? thanks you

Was it helpful?

Solution

the classes you should import for just posting to facebook wall should be:

//the first two what you are looking for.
import com.facebook.Request;
import com.facebook.Request.Callback;

//the rest are important to complete the posting task
import com.facebook.RequestAsyncTask;
import com.facebook.Response;
import com.facebook.Session;

none of you have mentioned are Facebook class! did you add Facebook sdk to your project?

Update

here is a function I use everytime I want to post to user's timeline:

public static void postFB(final Context context, String message) {

    final List<String> PERMISSIONS = Arrays.asList("publish_actions");

    Session session = Session.getActiveSession();

    if(session != null) {

        List<String> permissions = session.getPermissions();
        if(session.isOpened() && isSubset(PERMISSIONS, permissions)) {

            Request request = Request.newStatusUpdateRequest(session, message, new Callback() {

                @Override
                public void onCompleted(Response response) {
                    // TODO Auto-generated method stub
                    FacebookRequestError error = response.getError();
                    if(error != null)
                        //show toast of the error
                    else
                        //show toast that it is posted
                }
            });

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

        }

    }

}

isSubset function is used to check whether you have the permission to post or not:

public static boolean isSubset(Collection<String> subset, Collection<String> superset) {
    for (String string : subset) {
        if(!superset.contains(string))
            return false;
    }
    return true;
}

just call this the Post method passing it the context and message... you have to put in mind that you have already added the publish permission when the user logged in...

as @gain1200 said, it is better to check the facebook documents here is a good example of how to set it up

OTHER TIPS

Neither of those!!

The class Request that you're referring to is a class provided by the Facebook SDK for Android. Check out this reference page.

If you download the SDK and look at the source you'll find the definition for Request.java within com.facebook.*

so import com.facebook.*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top