1

I am working on an application where I need to integrate the social functionality of Facebook.

What I want is to use the SSO(Single Sign On) functionality and when the user press a button in my app, a webview will open and show him my app page in Facebook, after the user authenticated and now he could do like of other things as authenticated user.

I downloaded the Facebook SDK and includes it in my project, I also signed my application in the Facebook developers page and get an APP-ID.

This is how my code looks like till now:

public class WebViewLike extends Activity {

    private static final String TAG = "WebViewLike";
    public static final String APP_ID = "1222222";
    private Facebook facebook = new Facebook(APP_ID);

    private WebView webView;
    private Activity myActivity;

    private final class WallWebChromeClient extends WebChromeClient {

        public void onProgressChanged(WebView view, int progress)   
        {
            myActivity.setTitle("Loading...");
            myActivity.setProgress(progress * 100);

            if(progress == 100)
                myActivity.setTitle(R.string.app_name);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.view_weblike);
        myActivity = this;

        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {

                Log.d(TAG, "onComplete");
                Log.d(TAG, "facebook.getAccessToken() " + facebook.getAccessToken());
                Log.d(TAG, "facebook.getAccessExpires() " + facebook.getAccessExpires()); 

                //Load the given URL
                webView.loadUrl(getFacebookWallUrl());
            }

            @Override
            public void onFacebookError(FacebookError error) {Log.d(TAG, "onComplete");}

            @Override
            public void onError(DialogError e) {Log.d(TAG, "onComplete");}

            @Override
            public void onCancel() {Log.d(TAG, "onComplete");}
        });

        initWebView();
    }

    private void initWebView() {
        webView = (WebView) findViewById( R.id.likeWebView );
        final WebSettings webSettings = webView.getSettings(); 
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setHorizontalScrollBarEnabled(false);
        webView.setWebChromeClient(new WallWebChromeClient());
    }

    private String getFacebookWallUrl() {

        Log.d(TAG, "facebook.getAccessToken() != null");
        String wallUrl = "http://www.facebook.com/plugins/login.php?" + "href="
                + URLEncoder.encode("http://www.facebook.com/MyAppPage") + "&access_token="
                + URLEncoder.encode(facebook.getAccessToken());

        Log.d(TAG, "wallUrl " + wallUrl);
        return wallUrl;
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "onActivityResult");
        facebook.authorizeCallback(requestCode, resultCode, data);
    }
}

For now when I press the button, I move to a new activity that says that I'm already authorized, what means that the SSO works fine. The problem is when I press the Okay button, as I said, I want to move to my app page, but all the things I tried show me my Facebook application page, but asks me to login again. From my point of view I need to change the beginning of the wallUrl string at the getFacebookWallUrl() method, but I can't find any information about it.

Is it possible?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ofir A.
  • 3,112
  • 11
  • 57
  • 83

2 Answers2

1

Are you sharing something about your app through social network? If your answer is yes then try this.

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
Sathish
  • 1,147
  • 3
  • 10
  • 20
  • Not sharing anything, just want the user see my application page and that he have the ability to do like or other things, like read comments or post comments. – Ofir A. Jun 20 '12 at 10:34
0

You can use fbrocket api for Facebook integration like the following example. I am using it successfully.

http://www.androidpeople.com/android-facebook-api-example-using-fbrocket/#idc-cover

Yogesh Somani
  • 2,624
  • 3
  • 21
  • 34
  • I don't want to post status, I just want to show to the user my facebook page, without any login needed. From what I see fbrocket is for post status. Thanks. – Ofir A. Jun 20 '12 at 13:06