using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Facebook.Unity;
using System;
using System.Collections.Generic;
using Facebook.MiniJSON;
public class FaceBookManager : MonoBehaviour
{
List readPermission = new List () { "public_profile", "user_friends", "user_games_activity" },
publishPermission = new List () { "publish_actions" };
public PurchaseMenu purchaseMenu;
public string androidLinkShare,iosLinkShare;
public string rateLink;
public enum STATE
{
SHARE,
INVITE}
;
private STATE currentState;
// Use this for initialization
void Start ()
{
InitFB ();
}
// Update is called once per frame
void Update ()
{
}
private void InitFB ()
{
if (!FB.IsInitialized) {
FB.Init (InitCallback, onHideUnity);
} else {
FB.ActivateApp ();
}
}
private void InitCallback ()
{
if (FB.IsInitialized) {
//PrintLog("Initialized !");
} else {
//PrintLog("Failed to Initialize the Facebook SDK!");
}
}
// Perform Unity Tasks When App is Connecting To Facebook
private void onHideUnity (bool isGameShown)
{
if (!isGameShown) {
// Pause the game - we will need to hide
Time.timeScale = 0;
} else {
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
public void ShareOnFB ()
{
currentState = STATE.SHARE;
#if UNITY_IOS
string shareLink = iosLinkShare;
#endif
#if UNITY_ANDROID
string shareLink = androidLinkShare;
#endif
if (FB.IsLoggedIn) {
FB.ShareLink (
contentURL: new Uri (ShareLink),
callback: delegate (IShareResult shareRes) {
if (string.IsNullOrEmpty (shareRes.Error) && !shareRes.Cancelled) {
if (PlayerPrefs.GetInt ("Share") == 0) {
GameData.AddCash (1);
purchaseMenu.UpdateCash ();
PlayerPrefs.SetInt ("Share", 1);
}
} else
Debug.Log ("Posting Unsuccessful!");
}
);
} else
LoginFB ();
}
void LoginFB ()
{
if (FB.IsLoggedIn) {
Debug.Log ("Logged In !");
} else {
FB.ActivateApp ();
FB.LogInWithReadPermissions (readPermission, LoginCallback);
}
}
//Callback method of login
void LoginCallback (ILoginResult result)
{
if (FB.IsLoggedIn) {
Debug.Log ("Logged In Successfully!");
if (currentState == STATE.SHARE)
ShareOnFB ();
else if (currentState == STATE.INVITE)
NativeInviteFriendsFB ();
} else {
Debug.Log ("User cancelled login");
}
}
// Native Invite!
public void NativeInviteFriendsFB ()
{
currentState = STATE.SHARE;
if (FB.IsLoggedIn) {
FB.AppRequest (
"Let's play zombie street trsigger", null, null, null, null, null, "Let's play",
callback: delegate (IAppRequestResult result) {
if (result.RawResult != null) {
if (DeserializeJSONFriends (result.RawResult) != "")
if (GetFriendList (DeserializeJSONFriends (result.RawResult)).Count > 0) {
if (PlayerPrefs.GetInt ("Invite") == 0) {
GameData.AddCash (1);
purchaseMenu.UpdateCash ();
PlayerPrefs.SetInt ("Invite", 1);
}
}
}
});
} else
LoginFB ();
}
public void Rate ()
{
Application.OpenURL (rateLink);
}
public string DeserializeJSONFriends (string response)
{
string friendID = "";
var dict = Json.Deserialize (response) as IDictionary;
friendID = dict ["to"].ToString ();
return friendID;
}
private List GetFriendList (string _friend)
{
List friendList = new List ();
if (_friend.Contains (",")) {
string[] _str = _friend.Split (',');
for (int i = 0; i < _str.Length; i++) {
friendList.Add (_str [i]);
}
} else
friendList.Add (_friend);
return friendList;
}
}
What I have tried:
change sharelink to Sharelink but there is no change