为获取Android原生的应用程序Facebook的图形数据应用程序、图形、数据、Android

2023-09-06 16:10:32 作者:墨迹

我创建一款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 useExample

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