Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过以下方法获取facebook用户id和电子邮件、姓名_Android_Facebook Graph Api - Fatal编程技术网

Android 如何通过以下方法获取facebook用户id和电子邮件、姓名

Android 如何通过以下方法获取facebook用户id和电子邮件、姓名,android,facebook-graph-api,Android,Facebook Graph Api,我如何在下面的getProfileInformation()中获取facebook用户id和电子邮件,名称,在这里我想获取用户id,并希望在toast消息中显示,同时在run()中显示电子邮件和名称 您可以在请求中传递捆绑包中的必填字段: public void getProfileInformation() { Bundle params = new Bundle(); params.putString("fields", "id,name,email"); mAsy

我如何在下面的getProfileInformation()中获取facebook用户id和电子邮件,名称,在这里我想获取用户id,并希望在toast消息中显示,同时在run()中显示电子邮件和名称


您可以在请求中传递捆绑包中的必填字段:

public void getProfileInformation() {
    Bundle params = new Bundle();
    params.putString("fields", "id,name,email");

    mAsyncRunner.request("me", params, new RequestListener() {
    @Override
    public void onComplete(String response, Object state) {
        Log.d("Profile", response);
        String json = response;
        try {
            JSONObject profile = new JSONObject(json);
            // getting name of the user
            final String name = profile.getString("name");
            // getting email of the user
            final String email = profile.getString("email"); 
            final Long id = profile.getLong("id");
            runOnUiThread(new Runnable() {
                @Override
                public void run() { 
                    Toast.makeText(getApplicationContext(), "ID:" + id + "\nName: " + name + "\nEmail: " + email , Toast.LENGTH_LONG).show();
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
...

请注意,您将需要“电子邮件”权限。

是否可以获得代码中所示的类似电子邮件和名称的用户id?是的,您可以使用访问名称和电子邮件的相同方式访问id:Long id=profile.getLong(“id”);我不明白你在问什么,请澄清。试试{JSONObject profile=new JSONObject(json);//获取用户的名称最终字符串name=profile.getString(“name”);//获取用户的电子邮件最终字符串email=profile.getString(“email”);在这段代码中,我收到了电子邮件和用户姓名(在我的应用程序中使用facebook详细信息登录的用户),我如何才能获得用户id??
public void getProfileInformation() {
    Bundle params = new Bundle();
    params.putString("fields", "id,name,email");

    mAsyncRunner.request("me", params, new RequestListener() {
    @Override
    public void onComplete(String response, Object state) {
        Log.d("Profile", response);
        String json = response;
        try {
            JSONObject profile = new JSONObject(json);
            // getting name of the user
            final String name = profile.getString("name");
            // getting email of the user
            final String email = profile.getString("email"); 
            final Long id = profile.getLong("id");
            runOnUiThread(new Runnable() {
                @Override
                public void run() { 
                    Toast.makeText(getApplicationContext(), "ID:" + id + "\nName: " + name + "\nEmail: " + email , Toast.LENGTH_LONG).show();
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
...