Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 aman_jha · Aug 24, 2014 at 11:48 PM · c#androidiosfacebookconnection

Unity Like Facebook Page through app

Hi Unitarians,

I have an android app, and I have a button that I want my users to click to go to my facebook page and like it. If I use Application.OpenURL("https://www.facebook.com/youthquality");, then it goes through the browser, which isn't ideal. I want it so that so it goes to the facebook app, if it is on the phone. I use the following code that works mostly:

 void Facebook () {
 
         #if UNITY_EDITOR
             Application.OpenURL("https://www.facebook.com/xxx");
 
         #elif UNITY_IPHONE
             Debug.Log("Unity iPhone");
 
         #else
             if(checkPackageAppIsPresent("com.facebook.katana")) {
                 Application.OpenURL("fb://profile/xxx"); //there is Facebook app installed so let's use it
             }
             else {
                 Application.OpenURL("https://www.facebook.com/xxx"); // no Facebook app - use built-in web browser
             }
 
         #endif
     }
 
     private bool checkPackageAppIsPresent(string package)
     {
         AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
         AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
         
         //take the list of all packages on the device
         AndroidJavaObject appList = packageManager.Call<AndroidJavaObject>("getInstalledPackages",0);
         int num = appList.Call<int>("size");
         for(int i = 0; i < num; i++)
         {
             AndroidJavaObject appInfo = appList.Call<AndroidJavaObject>("get", i);
             string packageNew = appInfo.Get<string>("packageName");
             if(packageNew.CompareTo(package) == 0)
             {
                 return true;
             }
         }
         return false;
     }

The problem with the code is that it opens the facebook app, but it goes tot he newsfeed, and not to my page. How would I make it go to my page?

My actual page has a set name that I put, not numbers. It is not a profile, it is a page.

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

3 Replies

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

Answer by federicogr · Dec 24, 2014 at 07:22 AM

I use only this line:

Application.OpenURL("fb://page/375158539307294");

And worked like a charm for me. One thing to note: while my page's address is https://www.facebook.com/foxy.the.game fb://page/foxy.the.game didn't work when I tested. Use your Facebook Page ID instead.

Go to https://www.facebook.com/yourpage/info?tab=page_info and at the bottom, you will see your Facebook Page ID

Comment
Add comment · Show 9 · 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 nawash · Mar 28, 2015 at 07:24 AM 1
Share

and if you are not the ad$$anonymous$$ of the page, of it in a browser, open page soure and search for pageID

avatar image rguajardo · Jul 14, 2015 at 10:05 PM 0
Share

is there any way to know if the the user already like the page?

avatar image federicogr rguajardo · Jul 16, 2016 at 02:50 PM 1
Share

Yes! check my code (the user has to be logged):

 private void CheckUserLikes ()
 {
     FB.API(
         query: "/me/likes/375158539307294",
         method: Facebook.Http$$anonymous$$ethod.GET,
         callback: APICallback);
 }
 
 private void APICallback (FBResult result)
 {
     if (DeserializeJSONPage(result.Text))
     {
         isFacebookFan = true;
     }
 }
avatar image KristianBalaj · Jul 16, 2016 at 10:51 AM 0
Share

It woks perfect! But what will this do if Facebook app is not in the device, or how to make open FB in browser if there is not FB app?

avatar image federicogr KristianBalaj · Jul 16, 2016 at 02:46 PM 2
Share

This was my solution (only android):

in my share button:

 #if UNITY_ANDROID
 if(checkPackageAppIsPresent("com.facebook.katana"))
 {
     Application.OpenURL("fb://page/375158539307294"); //there is Facebook app installed so let's use it
 }
 else
 {
     Application.OpenURL("https://www.facebook.com/foxy.the.game"); // no Facebook app - use built-in web browser
 }
 #endif

and the function:

 #if UNITY_ANDROID
 private bool checkPackageAppIsPresent(string package)
 {
     AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
     AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
     AndroidJavaObject package$$anonymous$$anager = ca.Call<AndroidJavaObject>("getPackage$$anonymous$$anager");
         
     //take the list of all packages on the device
     AndroidJavaObject appList = package$$anonymous$$anager.Call<AndroidJavaObject>("getInstalledPackages",0);
     int num = appList.Call<int>("size");
     for(int i = 0; i < num; i++)
     {
         AndroidJavaObject appInfo = appList.Call<AndroidJavaObject>("get", i);
         string packageNew = appInfo.Get<string>("packageName");
         if(packageNew.CompareTo(package) == 0)
         {
             return true;
         }
     }
     return false;
 }
 #endif







avatar image UsamaAhmedKhan · Apr 18, 2017 at 11:58 PM 0
Share

Ins$$anonymous$$d of UNITY_ANDROID now below works

UNITY_ANDROID && !UNITY_EDITOR

avatar image shipan1382 · Nov 23, 2017 at 02:45 PM 0
Share

how to DeserializeJSONPage result ?? please help me.

avatar image federicogr shipan1382 · Nov 24, 2017 at 12:50 PM 0
Share

Here is the function:

 public static bool DeserializeJSONPage (string response)
     {
         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
         object nameH;
         return responseObject.TryGetValue("data", out nameH);
     }

avatar image shipan1382 federicogr · Nov 25, 2017 at 04:36 AM 0
Share

facebook sdk 7.8 does not support FBResult and resutl.Text so, what can i use?

my code.. if(isLoggedIn) { //facebook like FB.API ("/me/likes?fields=1065154363548853",Http$$anonymous$$ethod.GET,APICallback); } private void APICallback (IResult result) {

         if(DeserializeJSONPage(result.RawResult))
         {
             isFacebookFan = true;
             Debug.Log (result.ToString());
             if(isFacebookFan)
             {
                 isLiked.text = "You are liked";
             }
             else
             {
                 isLiked.text = "You are not liked";
             }
         }
 }
avatar image
2

Answer by tim-bluenose · Feb 07, 2018 at 04:59 PM

We found that /page/ opened the facebook app, but not the proper page.

We had to use /profile/ instead. Perhaps it has something to do with the type of page being linked to?

Application.OpenURL("fb://profile/XXXXXXX");

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 SohailBukhari · Sep 02, 2016 at 03:14 PM

how to DeserializeJSONPage result ??

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

28 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

Related Questions

I can see/send invites to non-app user friends on canvas app but not on android/ios 0 Answers

FB Gift Requests not appearing as Push Notification 0 Answers

Constant Input.Accelerometer Updater for Mobile? 0 Answers

Facebook - Is it possible to logout other active sessions? 0 Answers

How to launch built-in/first party applications using c# in Unity project (for both Android and iOS)? 0 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