移动到Facebook应用程序页面,通过单点登录认证后, [英] Move to the Facebook application page after authenticate through Single Sign On

查看:431
本文介绍了移动到Facebook应用程序页面,通过单点登录认证后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,我需要整合Facebook的社交功能的应用程序。

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

我要的是使用SSO(单点登录)功能,当用户preSS在我的应用程序按钮,web视图会打开并显示他在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.

我下载了Facebook的SDK,包括它在我的项目,我也签我的应用程序在Facebook的开发者页面,并得到一个APP-ID。

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.

这是我的code样子至今:

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

现在,当我preSS的按钮,我移动到一个新的活动,说我已经授权的,有什么意味着SSO工作正常。问题是,当我preSS奥凯按钮,正如我所说,我想要移动到我的应用程序页面,但所有的事情我想告诉我我的Facebook应用程序页面,但要求我再次登录。从我的角度来看,我需要改变 wallUrl 字符串在 getFacebookWallUrl()法的开始,但我无法找到关于它的任何信息。

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.

这可能吗?

推荐答案

您分享一些关于你的应用程序通过社交网络?如果你的答案是肯定的,然后尝试<一href="http://support.addthis.com/customer/portal/articles/381271-addthis-for-android-quickstart-guide#.T-Gl1PXeDIU"相对=nofollow>这个。

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

这篇关于移动到Facebook应用程序页面,通过单点登录认证后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆