1

I am trying to integrate Facebook to my Android app for social post. I have downloaded latest Facebook sdk from here and apply all setup require to post to facebook. Now i can post to facebook. But problem is that, when i run sample program from facebook sdk, a browser like page is open and user have to enter message himself there. but i dont want this page to showed up. i want a fixed message to post directly without opening facebook dialog box. But if there is noway to avoid this, please tell me how can i fixed certain part of message so that user can't modified it. Thanks in Advance

EDIT1: this is message i got after using this project

04-10 11:44:34.691: I/dalvikvm(719): Failed resolving Lnet/xeomax/TestRocket/TestRocket; 

>interface 22 'Lnet/xeomax/FBRocket/LoginListener;'

>04-10 11:44:34.691: W/dalvikvm(719): Link of class 'Lnet/xeomax/TestRocket/TestRocket;' failed

>04-10 11:44:34.691: D/AndroidRuntime(719): Shutting down VM

>04-10 11:44:34.701: W/dalvikvm(719): threadid=1: thread exiting with uncaught exception (group=0x40015560)

>04-10 11:44:34.781: E/AndroidRuntime(719): FATAL EXCEPTION: main

>04-10 11:44:34.781: E/AndroidRuntime(719): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.xeomax.TestRocket/net.xeomax.TestRocket.TestRocket}: java.lang.ClassNotFoundException: net.xeomax.TestRocket.TestRocket in loader dalvik.system.PathClassLoader[/data/app/net.xeomax.TestRocket-1.apk]

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.os.Handler.dispatchMessage(Handler.java:99)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.os.Looper.loop(Looper.java:130)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread.main(ActivityThread.java:3683)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at java.lang.reflect.Method.invokeNative(Native Method)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at java.lang.reflect.Method.invoke(Method.java:507)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at dalvik.system.NativeStart.main(Native Method)

>04-10 11:44:34.781: E/AndroidRuntime(719): Caused by: java.lang.ClassNotFoundException: net.xeomax.TestRocket.TestRocket in loader dalvik.system.PathClassLoader[/data/app/net.xeomax.TestRocket-1.apk]

>04-10 11:44:34.781: E/AndroidRuntime(719):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)

>04-10 11:44:34.781: E/AndroidRuntime(719):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

>04-10 11:44:34.781: E/AndroidRuntime(719):     ... 11 more

EDIT 2 : By introducing minute changes, now i can get rid of above errors. just add folder "libs" to the project and add "fbrocket-0.1a.jar" in this folder. Thank you very much everyone for spending time to help me.

someone_ smiley
  • 1,006
  • 3
  • 23
  • 42
  • I think this will never possible, without login page, you can never post the message to facebook. i am not sure and i too eager to know the answer for this. – RAAAAM Apr 10 '12 at 04:23
  • login page is fine. but i dont want message editing page that show-up when user post messages – someone_ smiley Apr 10 '12 at 04:35
  • @someone_smiley: what you actualy want ? Just login page comes and then if the message is posted then it shows the message that Message posted and if not then Mesasge is not posted. right ??? – Shreyash Mahajan Apr 10 '12 at 04:42
  • yes. i just dont want user to be able to edit any message. there will be fixed message inside program itself. when user press "POST". it simply post message directly without asking user to enter message. – someone_ smiley Apr 10 '12 at 04:51

4 Answers4

3

You can do this very easily by adding one jar file and the follow some simple steps. You must have a developer account on facebook. The complete information about your question is available on Facebook sharing of text and images on this link. See the answer given by me at there.

Community
  • 1
  • 1
Naresh Sharma
  • 4,323
  • 7
  • 48
  • 68
2

use FacebookRocket API http://www.androidpeople.com/android-facebook-api-example-using-fbrocket#idc-cover if u use this api facebook login page only come try this

try following code

     import net.xeomax.FBRocket.FBRocket;
     import net.xeomax.FBRocket.Facebook;
     import net.xeomax.FBRocket.LoginListener;
     import net.xeomax.FBRocket.ServerErrorException;
     import android.app.Activity;
     import android.os.Bundle;



    public class Fbook extends Activity implements LoginListener {

private FBRocket fbRocket;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    shareFacebook();
}

public void shareFacebook() {
    fbRocket = new FBRocket(this, "PitchFork TRY",
            "xxxxxxxxxxxxxxxxxxxx");

    if (fbRocket.existsSavedFacebook()) {
        fbRocket.loadFacebook();
    } else {
        fbRocket.login(R.layout.searchlist_view);
    }
}




public void onLoginFail() {
    fbRocket.displayToast("FaceBook Login failed!");
    fbRocket.login(R.layout.searchlist_view);
}

public void onLoginSuccess(Facebook facebook) {

    fbRocket.displayToast("FaceBook Login success!");
    try {
    final BaseApplication mlisturl = (BaseApplication)   getApplication();
        facebook.setStatus("posting ur custom status :::::::::::::::"
                +"data");
        fbRocket.displayDialog("Status Posted Successfully!! "
                + facebook.getStatus());
    } catch (ServerErrorException e) {
        if (e.notLoggedIn()) {
            fbRocket.login(R.layout.searchlist_view);
        } else {
            System.out.println(e);
        }
    }
}

}

K.Muthu
  • 1,232
  • 1
  • 17
  • 38
2

Its not possible.

You must have to login into facebook accountto post the message on Facebook.

Your requirement is only possible if you stored the facebook id and password staticaly in to the application.

Well but there is one alternate of it. If you use facebook sdk to implement the post message on Facebook then it may help you. With using that you can only able to get the facebook login screen once. If user has registered with that login id and password then it will never come again and simple send varification toast message that the message is posted on facebook.

For the above example refer this examples.

  1. Example 1
  2. Example 2
  3. Demo Example
  4. Example 4

Hope it will help you. If not then let me know.

Enjoy. :)

Updated

For to post the static message on facebook, do like below after integrating the Facebook sdk in to the project:

System.out.println("Message is: "+postMessage); // My static post message

                        facebook.authorize(MainActivityPage.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {                     
                            @Override                     
                            public void onComplete(Bundle values) {   

                                Bundle params = new Bundle();              
                                params.putString(Facebook.TOKEN, facebook.getAccessToken());              
                                params.putString("message", postMessage);               

                                AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);              
                                mAsyncRunner.request("me/feed", params, "POST", new SampleUploadListener(),null);

                                Toast.makeText(getApplicationContext(), "Message Posted on Facebook.", Toast.LENGTH_SHORT).show();
                            }                      
                            @Override                     
                            public void onFacebookError(FacebookError error) {}                      
                            @Override                     
                            public void onError(DialogError e) {}                      
                            @Override                     
                            public void onCancel() {}                 
                        });
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • thanks for helping. i am ok with FB login page. what i am avoiding is that the window that pop up for user to edit the message to post. I want fixed message to be post and don't want user to edit it. – someone_ smiley Apr 10 '12 at 04:42
  • @someone_smiley: which example you are using ? Is edit Post message window coming from the part of the Facebook sdk ?? Please check it. – Shreyash Mahajan Apr 10 '12 at 04:53
  • I have already try 3rd .... just try to modify it so that fixed message can post to FB without asking user to manually enter the text – someone_ smiley Apr 10 '12 at 05:00
  • @someone_smiley: Ok. That example works fine. And for to send message without asking to user to edit it, you have to manually set it. – Shreyash Mahajan Apr 10 '12 at 05:21
  • @someone_smiley: My answer works for you or the nares's Answer ? – Shreyash Mahajan Apr 11 '12 at 04:22
  • Hi iDroid Explorer, i have gone through 3 example above and also your code. sorry am unable to get it run without errors as i am very new to android as well as java(its been only a week for both of them!), this make me unfamiliar to error messages and solution to it. so i back to naresh's link again because i feel am close to getting it. with some more research, i found out that i just need to add "libs" folder and add .jar library to it. But am appreciate your efforts, your example above give me more experiance on the subject, thats why i vote up this post. Thank you again :) – someone_ smiley Apr 11 '12 at 04:44
  • @someone_smiley : OK. Keep coding. . . Enjoy. :) – Shreyash Mahajan Apr 11 '12 at 04:48
  • hey idroid....after trying all tutorial post in this question, i found your EXAMPLE 2 proved to be best among all :), ....thank you once again :) – someone_ smiley Apr 12 '12 at 08:04
  • @someone_smiley: yes, thank You. If it helps you to solve your issue then you have to accept it. Instead of other so other can navigate to right one answer. – Shreyash Mahajan Apr 12 '12 at 09:00
  • i suggest you edit the post and leave only example 2 alive... so that people get to it quickly without spending much time on it – someone_ smiley Apr 12 '12 at 10:28
  • @someone_smiley: Actually i have remain all as because may be someone wants any other issue and get solution from that example. Anyway Thanks. Enjoy Coding. :) – Shreyash Mahajan Apr 12 '12 at 12:25
1

Try this

public void postMessageOnWall(String msg) {
    if (facebook.isSessionValid()) {
        Bundle parameters = new Bundle();
        parameters.putString("message", msg);
        try {
            String response = facebook.request("me/feed", parameters,"POST");
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        login();
    }
}

Do follow the link

RAAAAM
  • 3,378
  • 19
  • 59
  • 108