Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using Facebook.Unity;
- using System.Collections;
- using System.Collections.Generic;
- public class FacebookScript : MonoBehaviour
- {
- IEnumerable<string> facebook_permissions = new string[] { "public_profile", "email", "user_friends", "publish_actions" };
- // Use this for initialization
- void Awake()
- {
- FB.Init(SetInit, OnHideUnity);
- Debug.Log("FB Init done");
- }
- private void SetInit()
- {
- if (FB.IsLoggedIn == true)
- {
- Debug.Log("Logged in");
- }
- }
- private void OnHideUnity(bool isGameShown)
- {
- if (isGameShown == false)
- {
- Time.timeScale = 0;
- }
- else
- {
- Time.timeScale = 1;
- }
- }
- public void FBLogin()
- {
- FB.LogInWithReadPermissions(facebook_permissions, AuthCallback);
- }
- private void AuthCallback(ILoginResult result)
- {
- if (FB.IsLoggedIn) // Logged in.
- {
- // AccessToken class will have session details
- var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
- // Print current access token's User ID
- Debug.Log(aToken.UserId);
- // Print current access token's granted permissions
- foreach (string perm in aToken.Permissions)
- {
- Debug.Log(perm);
- }
- APIPost();
- Share();
- }
- else
- {
- Debug.Log("User cancelled login");
- }
- }
- public void APIPost()
- {
- Dictionary<string, string> ScoreDictionary = new Dictionary<string, string>();
- ScoreDictionary.Add("score", PlayerPrefs.GetInt("Highscore", 0).ToString());
- FB.API("/me/scores", HttpMethod.POST, POSTCallback, ScoreDictionary);
- }
- public void POSTCallback(IGraphResult result)
- {
- Debug.Log(result.Error);
- NPBinding.UI.ShowToast("POSTCallback Error: " + result.Error, VoxelBusters.NativePlugins.eToastMessageLength.LONG);
- }
- public void Share()
- {
- FB.ShareLink(new System.Uri("https://play.google.com/store/apps/details?id=org.zewde.JumpyBall"),
- "I reached " + PlayerPrefs.GetInt("Highscore",0).ToString() + " on #JumpyBall. Can you beat me ? Try me!",
- "https://play.google.com/store/apps/details?id=org.zewde.JumpyBall",
- callback: ShareCallback);
- }
- private void ShareCallback(IShareResult result)
- {
- if (result.Cancelled || !string.IsNullOrEmpty(result.Error))
- {
- Debug.Log("ShareLink Error: " + result.Error);
- }
- else if (!string.IsNullOrEmpty(result.PostId))
- {
- // Print post identifier of the shared content
- Debug.Log(result.PostId);
- }
- else
- {
- // Share succeeded without postID
- Debug.Log("ShareLink success!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement