栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过Facebook成功登录后如何获取用户详细信息

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过Facebook成功登录后如何获取用户详细信息

在这里,

initFacebook()
您可以登录并执行您的功能,在这里,我正在获取用户的朋友信息。

private void initFacebook() {    try    {        if (APP_ID == null)         { Util.showalert(this,"Warning","Facebook Applicaton ID must be "+ "specified before running this example: see Example.java");        }        mFacebook = new Facebook();        mAsyncRunner = new AsyncFacebookRunner(mFacebook);        mFacebook.authorize(FacebookList.this, APP_ID, new String[] {"email", "read_stream", "user_hometown", "user_location","friends_about_me", "friends_hometown", "friends_location","user_relationships", "friends_relationship_details","friends_birthday", "friends_education_history","friends_website" }, new DialogListener()        { public void onComplete(Bundle values)  {     getHTTPConnection(); } public void onFacebookError(FacebookError error)  {     Log.i("public void onFacebookError(FacebookError error)....","...."); } public void onError(DialogError e)  {     Log.i("public void onError(DialogError e)....", "....");     CustomConfirmOkDialog dialog = new CustomConfirmOkDialog(FacebookList.this, R.style.CustomDialogTheme, Utils.FACEBOOK_CONNECTION_ERROR);     dialog.show(); } public void onCancel()  {     Log.i("public void onCancel()....", "...."); }        });        SessionStore.restore(mFacebook, this);        SessionEvents.addAuthListener(new SampleAuthListener());        SessionEvents.addLogoutListener(new SampleLogoutListener());    }    catch (Exception e)     {        e.printStackTrace();    }}

在中

getHTTPConnection()

,继续进行连接和发送字段,这是我们需要的关于用户朋友的条件,因为在这里我们可以看到传递的字段是
fields=id,first_name,last_name,location,picture
朋友。在这里,您可以根据应用程序的要求更改此字段。

private void getHTTPConnection() {    try    {        mAccessToken = mFacebook.getAccessToken();        HttpClient httpclient = new DefaultHttpClient();        String result = null;        HttpGet httpget = new HttpGet("https://graph.facebook.com/me/friends?access_token="+ mAccessToken + "&fields=id,first_name,last_name,location,picture");        HttpResponse response;        response = httpclient.execute(httpget);        HttpEntity entity = response.getEntity();        if (entity != null)         { result = EntityUtils.toString(entity); parseJSON(result);        }    }    catch (Exception e)     {        e.printStackTrace();    }}

现在,在成功连接到 Facebook之后 ,我们正在获取

JSON
数据并进一步对其进行解析。

private void parseJSON(String data1) throws Exception,NullPointerException, JSonException {    try     {        JSonObject jObj = new JSonObject(data1);        JSonArray jObjArr = jObj.optJSonArray("data");        int lon = jObjArr.length();        for (int i = 0; i < lon; i++)         { JSonObject tmp = jObjArr.optJSonObject(i); String temp_image =  tmp.getString("picture");    String temp_fname = tmp.getString("first_name"); String temp_lname = tmp.getString("last_name"); String temp_loc = null; JSonObject loc = tmp.getJSonObject("location"); temp_loc = loc.getString("name");        }    }     catch (Exception e)     {        Log.i("Exception1 is Here>> ", e.toString());        e.printStackTrace();    }}

假定您已经在应用程序中添加了一个 facebook jar,并且可以通过调用

initFacebook()

onCreate()
活动来继续执行此代码。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/509194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号