1

Facebook と統合して、グラフを使用して写真、名、その他の情報を取得する Android ゲームを作成しています。完全に機能する以下のコードを使用して写真を取得する方法を見つけましたが、機能するのに苦労していますfirst_name などの他の情報を抽出する例...

写真を取得して ImageView に表示するために使用しているコードは次のとおりです。

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 開発者 Web サイト ( https://developers.facebook. com/docs/reference/api/ ) しかし、実際の例が見つかりません。

テキストビューに表示できるように、ユーザーの first_name を取得する実際の例を誰かに見せてもらえますか?

4

2 に答える 2

4

このURL"https://graph.facebook.com/me/friends?access_token="+accessTokenを使用して、名前とIDを含む友達を取得して、それらの情報を取得できます `"https://graph.facebook.com/"+yourFriendId+"?access_token="+accessToken' を使用するだけで、jsonが返されます解析して使用できる

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();
            }
于 2012-06-19T21:19:45.047 に答える
0

リクエスト URL を just /me(つまりhttps://graph.facebook.com/me?type=normal&method=GET&access_token=...) に変更すると、現在認証されているユーザーの利用可能なすべてのプロファイル情報が取得されます。

この JSON オブジェクトには、ここにあるその他の属性の中でもfirst_name、およびが含まれている必要があります。last_name

この便利な API エクスプローラー ツールをチェックして、表示される内容を試してみてください。

于 2012-06-19T21:21:27.013 に答える