繁体   English   中英

如何解决此问题以显示来自 facebook 登录的电子邮件、生日好友?

[英]How to fix this problem to display email, birthday friends from facebook login?

我正在尝试登录 facebook。 但我无法显示电子邮件,朋友,生日。 我丢了

一些东西,但无法找到问题。 我认为围绕“请求”,可能是错误的。 请帮忙 。 这是输出>这是代码:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fb_login)

        callbackManager = CallbackManager.Factory.create()

        email = findViewById(R.id.txtEmail)
        birthday = findViewById(R.id.txtBirthday)
        friends = findViewById(R.id.txtFriends)
        profile = findViewById(R.id.imgProfile)

        loginButton?.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday","user_friends"))

        loginButton?.registerCallback(callbackManager, object : FacebookCallback<LoginResult>{
            override fun onSuccess(loginResutl: LoginResult?) {
                mDialog = ProgressDialog(this@FbLoginActivity)
                mDialog!!.setMessage("Retrieving Data")
                mDialog!!.show()

                request = GraphRequest.newMeRequest(loginResutl!!.accessToken, object : GraphRequest.GraphJSONObjectCallback {

                    override fun onCompleted(`object`: JSONObject?, response: GraphResponse?) {
                        mDialog!!.dismiss()

                        getData(`object`!!)
                    }

                })

                //Request graph APi

                var parameters : Bundle ?= null
                parameters!!.putString("fields", "id,email,birthday,friends")

                request!!.setParameters(parameters)
                request!!.executeAsync()
            }

            override fun onCancel() {

            }

            override fun onError(error: FacebookException?) {

            }

        })
    }

    private fun getData(`object`: JSONObject) {
        var profile_picture = URL("https://graph.facebook.com/"+`object`.getString("id")+"/picture?width=250&height=250")

        Picasso.get().load(profile_picture.toString()).into(profile)

        email!!.setText(`object`.getString("email"))
        birthday?.setText(`object`.getString("birthday"))
        friends?.setText("Friends :" + `object`.getJSONObject("friends").getJSONObject("summary").getString("total_count"))

    }

Xml 文件:它显示 facebook 登录的 ui 详细信息。 在这个文件中有 facebook 的登录按钮。

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="30dp"
        tools:context=".FbLoginActivity">

    <ImageView
            android:id="@+id/imgProfile"
            android:layout_width="300dp"
            android:layout_height="300dp"
    />

    <TextView
            android:id="@+id/txtEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:hint="Email"
    />

    <TextView
            android:id="@+id/txtBirthday"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:hint="Birthday"
    />

    <TextView
            android:id="@+id/txtFriends"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:hint="Friends"
    />      

    <com.facebook.login.widget.LoginButton
            android:id="@+id/login_button"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

</LinearLayout>

如果用户通过电话号码登录,则电子邮件可能为空访问http://stackoverflow.com/questions/29517667/android-facebook-sdk-4-x-how-to-get-email-address-and-facebook -access-token-tohttp://stackoverflow.com/questions/29493486/create-a-request-in-facebook-sdk-4-android

Facebook 默认不给用户生日。您必须使用扩展权限并将您的应用提交给 Facebook 进行审核才能访问用户的生日。

看这里:

https://developers.facebook.com/docs/android/graph

Facebook 假定您的电子邮件无效。 要测试它,请使用 Graph API Explorer 并尝试获取它。 如果即使在那里您也无法收到您的电子邮件,请在您的个人资料设置中更改它,然后重试。

https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cemail&

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM