为获取Android原生的应用程序Facebook的图形数据 [英] Retrieving facebook graph data for android native app

查看:102
本文介绍了为获取Android原生的应用程序Facebook的图形数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一款Android游戏与Facebook集成,检索他们的照片和名字,并使用图形等信息,我发现了如何使用低于code这完美的作品,但我找回自己的照片M苦苦寻找像FIRST_NAME等提取等信息的工作示例...

I'm creating a android game that integrates with facebook to retrieve their photo and first name and other information using the graph, I've found out how to retrieve their photo using the below code which works perfectly but I'm struggling to find working examples of extracting other information like first_name etc...

在code我使用来获取照片并在ImageView的显示它在下面。

The code I'm using to retrieve the photo and display it in a ImageView is below.

public void showPhoto(View v) {
    try {
        ImageView MyProfilePicImageView = (ImageView)findViewById(R.id.temp);
        URL MyProfilePicURL = new URL("https://graph.facebook.com/me/picture?type=normal&method=GET&access_token="+ access_token );
        Bitmap MyprofPicBitMap = null;

        try {
            MyprofPicBitMap = BitmapFactory.decodeStream(MyProfilePicURL.openConnection().getInputStream());
            MyProfilePicImageView.setImageBitmap(MyprofPicBitMap);
        }
        catch (IOException e) {
            e.printStackTrace();
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

我已经搜查高和低,但似乎无法找到如何使用图表,其他信息意味着FIRST_NAME等等......这里包括Facebook的开发网站( https://developers.facebook.com/docs/reference/api/ ),但找不到工作示例。

I've searched high and low but can't seem to find information on how to retrieve the other information using the graph, other information meaning first_name etc... including here on the facebook developer website (https://developers.facebook.com/docs/reference/api/) but can't find a working example.

有人能告诉我一个工作的例子来获取用户的FIRST_NAME这样我就可以在一个TextView显示呢?

Can anybody show me a working example to retrieve the first_name of the user so I can display it in a textview?

推荐答案

使用这个网址https://graph.facebook.com/me/friends?access_token=+的accessToken 你可以得到你的朋友,其中包含thier名称和ID来获取信息的任何人只需使用`https://graph.facebook.com/\"+yourFriendId+\"?access_token=\"+accessToken
这将返回JSON可以解析和使用
例如

using this url"https://graph.facebook.com/me/friends?access_token="+accessToken you can get your friends which contains thier names and ids to get info about any of them just use `"https://graph.facebook.com/"+yourFriendId+"?access_token="+accessToken' this will return json that you can parse and use
Example

HttpClient httpclient = new DefaultHttpClient();
String url = "https://graph.facebook.com/me/friends?access_token=" + URLEncoder.encode(token);
HttpGet httppost = new HttpGet(url);
try {
                HttpResponse response = httpclient.execute(httppost);

                // to get the response string
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(
                                response.getEntity().getContent(), "UTF-8"));
                // used to construct the string
                String res = "";
                for (String line = null; (line = reader.readLine()) != null;) {
                    res += line + "\n";

                }
// here we will parse the response
                JSONObject obj = new JSONObject(new JSONTokener(res));
                JSONArray data = obj.getJSONArray("data");
int len = data.length();
for (int i = 0; i < len; i++) {
                    JSONObject currentResult = data.getJSONObject(i);
                    String name = currentResult.getString("name");
                    String icon = currentResult.getString("id");

                    // do what ever you want

                }
} catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

这篇关于为获取Android原生的应用程序Facebook的图形数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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