Android如何打开Facebook应用程序? [英] Android How to Open Facebook App?

查看:547
本文介绍了Android如何打开Facebook应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
从其他应用启动Facebook应用

Possible Duplicate:
launch facebook app from other app

我正在做一个Android项目,在该项目中,我需要获取Facebook用户详细信息,例如UserId,AccessToken.

I am doing one android project, In that project i need to get Facebook User Details like UserId,AccessToken.

使用Fcebook SDK完成Facebook集成.

Done Facebook Integration using Fcebook SDK.

现在,Facebook发布了 URL SCHEME 以打开Facebook应用程序并获取用户详细信息.

Now, Facebook Released URL SCHEME to open facebook application and get user details.

我就是这样,

long longFacebookUid = Long.parseLong(facebookUid);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id", facebookUid);
this.startActivity(intent);
return;

在此称为Facebook应用程序的代码中,此后我不知道如何获取userId和令牌.

In this code Called Facebook Application, After that i don't no How to get userId and Token.

谢谢.

推荐答案

在URL SCHEME之外,使用基于SDK的功能更为简单.但这可能不是您想要的答案.

Beside URL SCHEME, using the SDK based function is more simple.But it may not be the answer you want.

备注:以下信息基于facebook-android SDK 2.0(3.0现在可用)

Remarks: The following information is based on facebook-android SDK 2.0(3.0 is avaliable now)

运行授权功能(登录部分)后(以下是facebook文档中的示例代码)

After running the authorize function (Login Part)(The following is sample code in facebook document)

 facebook.authorize(this, new String[] {}, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putString("access_token", facebook.getAccessToken());
                editor.putLong("access_expires", facebook.getAccessExpires());
                editor.commit();
            }

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

为了获取访问令牌,只需在SDK 2.0中运行以下功能

In order to get the access token, just run the following function in SDK 2.0

String access_token=facebook.getAccessToken();

对于用户ID

public String GetUserID(){
    Bundle params = new Bundle();
    params.putString("fields", "id");
    String resp= "";
    try {
        resp = facebook.request("me", params, "GET");//call the request function in SDK 2.0, using graph api
    } catch (FileNotFoundException e) {
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    try{
        resp = new JSONObject(resp).getString("id");
    }catch(JSONException e1){
    }
    }
    return resp;
};

我认为这些是获得结果的最简单方法,但不使用URL SCHEME.

I think these are the most simply way to get the result, but not using the URL SCHEME.

希望它能为您提供帮助.

I hope it can help you.

这篇关于Android如何打开Facebook应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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