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 /
avatar image
0
Question by fazlarabby · Jul 20, 2016 at 08:56 PM · androidfacebookintegration

fb login works but invite share and challenge not working

Can anyone help me with the Facebook integration in unity for android game? After using the below script I found no error in the console so I built the apk and tested it on my phone. I can log in to Facebook from the game but the Invite and sharing options are not working also the challenge option isn't working. Is it got anything to do with the Facebook android app?

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 using Facebook.Unity;
 
 public class Test : MonoBehaviour {
     public GameObject LoggedInUI;
     public GameObject NotLoggedInUI;
     public GameObject Friend;
     private static string applink = "https://fb.me/846500322149000";/*"http://www.mdfazlarabby.speranzabd.com/upcomingprojects"*/
     void Awake(){
         if (!FB.IsInitialized) {
             FB.Init (InitCallBack);
         }
     }
 
     void InitCallBack(){
         Debug.Log ("FB has been initiased.");
         ShowUI ();
     }
 
     public void Login(){
         if (!FB.IsLoggedIn) {
             FB.LogInWithReadPermissions (new List<string>{ "user_friends" }, LoginCallBack);
         }
     }
 
     void LoginCallBack(ILoginResult result){
         if (result.Error == null) {
             Debug.Log ("FB has logged in.");
             ShowUI ();
         } else {
             Debug.Log ("Error during login: " + result.Error);
         }
     }
 
     void ShowUI(){
         if (FB.IsLoggedIn) {
             LoggedInUI.SetActive (true);
             NotLoggedInUI.SetActive (false);
             FB.API ("me/picture?width=100&height=100", HttpMethod.GET, PictureCallBack);
             FB.API ("me?fields=first_name", HttpMethod.GET, NameCallBack);
             FB.API ("me/friends", HttpMethod.GET, FriendCallBack);
             FB.GetAppLink (AppLinkCallback);
         } else {
             LoggedInUI.SetActive (false);
             NotLoggedInUI.SetActive (true);
         }
     }
 
     void PictureCallBack(IGraphResult result){
         Texture2D image = result.Texture;
         LoggedInUI.transform.FindChild ("ProfilePicture").GetComponent<Image> ().sprite = Sprite.Create (image, new Rect (0, 0, 100, 100), new Vector2 (0.5f, 0.5f));
     }
 
     void NameCallBack(IGraphResult result){
         IDictionary<string, object> profile = result.ResultDictionary;
         LoggedInUI.transform.FindChild ("Name").GetComponent<Text> ().text = "Hi There! " + profile ["first_name"];
     }
 
     public void LogOut(){
         FB.LogOut ();
         ShowUI ();
     }
 
     public void Share(){
         FB.ShareLink (new System.Uri ("http://www.mdfazlarabby.speranzabd.com/upcomingprojects/"), "This game is awesome!", "A description of the game.", new System.Uri("http://www.mdfazlarabby.speranzabd.com/wp-content/uploads/2016/07/BullsAdventure.jpg/"),ShareCallback);
     }
 
     private void ShareCallback (IShareResult result) {
         if (result.Cancelled) {
             Debug.Log ("Share cancelled.");
         } else if (!string.IsNullOrEmpty (result.Error)) {
             Debug.Log (" Error in Share" + result.Error);
         } else {
             Debug.Log ("Share was successful" +result.RawResult);
         }
 
     }
 
     public void Invite(){
         FB.Mobile.AppInvite (new System.Uri (applink), new System.Uri ("http://www.mdfazlarabby.speranzabd.com/wp-content/uploads/2016/07/BullsAdventure.jpg/"), InviteCallback);
     }
 
     void InviteCallback( IAppInviteResult result)
     {
         if (result.Cancelled) {
             Debug.Log ("Invite cancelled.");
         } else if (!string.IsNullOrEmpty (result.Error)) {
             Debug.Log (" Error in Invite" + result.Error);
         } else {
             Debug.Log ("Invite was successful" +result.RawResult);
         }
 
 
     }
 
     public void Challenge() 
     {
         FB.AppRequest ("Custom message", null, new List<object>{ "app users" }, null, null, "Data", "Challenge Your Friends!");
     }
     void ChallengeCallback(IAppRequestResult result){
         if (result.Cancelled) {
             Debug.Log ("Challenge cancelled.");
         } else if (!string.IsNullOrEmpty (result.Error)) {
             Debug.Log (" Error in Challenge" + result.Error);
         } else {
             Debug.Log ("Challenge was successful" +result.RawResult);
         }
     
     
     }
 
 
     void FriendCallBack(IGraphResult result){
         IDictionary<string, object> data = result.ResultDictionary;
         List<object> friends = (List<object>)data ["data"];
         foreach (object obj in friends) {
             Dictionary<string, object> dictio = (Dictionary<string, object>)obj;
             CreateFriend(dictio ["name"].ToString (), dictio ["id"].ToString ());
         }
     }
 
     void CreateFriend(string name, string id){
         GameObject myFriend = Instantiate (Friend);
         Transform parent = LoggedInUI.transform.FindChild ("ListContainer").FindChild ("FriendList");
         myFriend.transform.SetParent (parent);
         myFriend.GetComponentInChildren<Text> ().text = name;
         FB.API(id + "/picture?width=100&height=100", HttpMethod.GET, delegate(IGraphResult result) {
             myFriend.GetComponentInChildren<Image>().sprite = Sprite.Create (result.Texture, new Rect (0, 0, 100, 100), new Vector2 (0.5f, 0.5f));
         });
     }
 
     void AppLinkCallback (IAppLinkResult result)
     {
         if (string.IsNullOrEmpty (result.Error)) {
             Debug.Log ("Applink done: " + result.RawResult);
             IDictionary<string, object> dictio = result.ResultDictionary;
             if (dictio.ContainsKey ("target_url")) {
                 string url = dictio ["target_url"].ToString ();
                 string keyword = "request_ids=";
                 int k = 0;
                 while (k < url.Length - keyword.Length && !url.Substring (k, keyword.Length).Equals (keyword))
                     k++;
                 k += keyword.Length;
                 int l = k;
                 while (url [l] != '&' && url [l] != '%')
                     l++;
                 string id = url.Substring (k, l - k);
                 FB.API ("/" + id + "_" + AccessToken.CurrentAccessToken.UserId, HttpMethod.GET, RequestCallback);
         } else 
         {
             Debug.Log ("Applink Error :" + result.Error);
         }
     }
 
     
 }
     void RequestCallback(IGraphResult result){
         Debug.Log ("Request callback");
         if (string.IsNullOrEmpty (result.Error)) {
             IDictionary<string, object> dictio = result.ResultDictionary;
             if (dictio.ContainsKey ("data"))
                 Debug.Log (dictio ["data"]);
             if (dictio.ContainsKey ("id"))
                 FB.API ("/" + dictio ["id"], HttpMethod.DELETE, null);
         } else {
             Debug.Log ("Error in request:" + result.Error);
         }
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nnadiwisdom1 · Apr 01, 2017 at 06:58 AM

i also have a similar problem i think you need to get a privacy policy url. then enable public actions in developers acc.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem Integration Facebook with Unity 5 On Android 0 Answers

Facebook Integration for Android Game 1 Answer

is there any SINGLE plugin for both ios and android FACEBOOK itegration 2 Answers

Integration facebook with android unity 5 problem 0 Answers

Unity Android - Image share to facebook fails 1 Answer


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