Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sovan-k1 · Jul 06, 2017 at 04:33 PM · facebooklocationusernameage

fetch email, age, location from facebook sdk ?

Hello Friends,

I am working on a project in which I am using Facebook SDK. I want to fetch the first name, last name, gender, email, age and location(region) of the user logged in.

Though I got the profile pic, first name, last name, and gender, I am unable to fetch email, age, and location. Check the below script and let me know what's wrong with it. Genuine answers are appreciated.

using System.Collections; using System.Collections.Generic; using UnityEngine; using Facebook.Unity;

using UnityEngine.UI;

public class fbscript : MonoBehaviour {

 public GameObject DialogLoggedIn;
 public GameObject DialogLoggedOut;

 public Text Dialogusername;
 public Image DialogProfilePic;

 public Text DialogGender;
 public Text DialogBirthday;
 public Text DialogLocation;
 public Text DialogAge;

 void Awake()
 {
     FB.Init (SetInit, onHideUnity);

 }

 void SetInit()
 {
     if (FB.IsLoggedIn)
         Debug.Log ("fb is logged in SetInit method");
     else {
         Debug.Log ("fb is not logged in SetInit method");
     }
     dealWithFbMenus (FB.IsLoggedIn);
 }
 void onHideUnity(bool isGameShown)
 {
     if (!isGameShown)
         Time.timeScale = 0;
     else {
         Time.timeScale = 1;
     }
 }

 public void FBLogin()
 {
     List<string> permissions = new List<string>();
     permissions.Add ("public_profile");
     permissions.Add ("email");
     permissions.Add ("user_location");

     FB.LogInWithReadPermissions (permissions, AuthCallBack);
 }

 void AuthCallBack(IResult result)
 {
     if (result.Error != null) {

// Debug.Log (result.Error); // FB.LogInWithReadPermissions (permissions, AuthCallBack); } else {
if (FB.IsLoggedIn) { Debug.Log ("fb is logged in AuthCallBack method"); // Debug.Log (result.RawResult); } else { Debug.Log ("fb is not logged in AuthCallBack method"); } dealWithFbMenus (FB.IsLoggedIn); } }

 void dealWithFbMenus(bool isLoggedIn)
 {
     if (isLoggedIn) {
         DialogLoggedIn.SetActive (true);
         DialogLoggedOut.SetActive (false);


         FB.API ("/me?fields=name,gender", HttpMethod.GET, DisplayUserName);

         FB.API ("/me/picture?type=large", HttpMethod.GET, DisplayProfilePic);
         FB.API ("/me?fields=user_birthday,location,age", HttpMethod.GET, DisplayOtherDetails);
     } else {
         
         DialogLoggedIn.SetActive (false);
         DialogLoggedOut.SetActive (true);
     }
 }

 void DisplayUserName(IResult result)
 {
     Text username = Dialogusername;
     Text gender = DialogGender;

     if (result.Error == null) {

         username.text = "" + result.ResultDictionary ["name"];
         gender.text = "" + result.ResultDictionary ["gender"];
     } else {
         Debug.Log (result.Error);
     }
 }

 void DisplayProfilePic(IGraphResult result){
     Image profilePic;
     if (result.Texture != null) {
         profilePic = DialogProfilePic;
         profilePic.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 200, 199), new Vector2 ());
     }
 }

 void DisplayOtherDetails(IGraphResult result){
     Image profilePic;
     Text bday = DialogBirthday;
     Text loc = DialogLocation;
     Text age = DialogAge;
     if (result.Error == null) {
         bday.text = "" + result.ResultDictionary ["user_birthday"];
         bday.text = "" + result.ResultDictionary ["location"];
         bday.text = "" + result.ResultDictionary ["age"];
     }
 }

} //

Thanks,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by vir1234 · Jul 07, 2017 at 06:25 AM

email,age and location of user is not accessible in fb Graph API Explorer by default you have to give permission , You can Check also By Urself fb developer>ToolsAndSupport> Graph API Explorer . to Give Permission click on get token drop down and click on get user access token after clicking user access token you can see select permission, give user data permission check email and user_location check box in select permission . you can get email and birthday i m not sure about location

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sovan-k1 · Jul 18, 2017 at 01:10 PM

Thanks @vir1234

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Facebook SDK Json Parsing with foreach loop not updating 1 Answer

Failed to re-package resources 0 Answers

If you install the Google Play Game Plugin, you will not be able to sign in to Facebook. (iOS) 1 Answer

CommandInvokationFailure: Failed to re-package resources Mapbox/FB 0 Answers

MarshalDirectiveException: Cannot marshal type 'System.Collections.Generic.IEnumerable`1' 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges