Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Richard MacCutchan 19-Feb-18 4:51am    
contentURL: new Uri (ShareLink),
Where is this Uri defined?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900