hey guys, here is the Facebook sharing script, simple way, make sure you have to import Facebook SDK in your unity project,
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
public class Facebookmanager : MonoBehaviour {
//--------- login----------
void Awake()
{
if (!FB.IsInitialized)
{
FB.Init ();
}
else
{
FB.ActivateApp ();
}
}
public void LogIn()
{
FB.LogInWithReadPermissions (callback: OnLogIn);
}
void OnLogIn(ILoginResult result)
{
if (FB.IsLoggedIn)
{
AccessToken token = AccessToken.CurrentAccessToken;
}
else
{
Debug.Log("Canceled Login");
}
}
//------- login end-----------
//-----sharing start-------
public void Share()
{
FB.ShareLink (
contentTitle: "Mad Drift! Love this game!",
contentURL: new System.Uri ("https://yourlinkwhateveryoushare"),
contentDescription: "Mad Drift! Love this game! Download it rate it",
photoURL: new System.Uri ("https://photourl"),
callback: OnShare);
}
void OnShare (IShareResult result)
{
if (result.Cancelled || !string.IsNullOrEmpty (result.Error))
{
Debug.Log ("ShareLinkError: " + result.Error);
}
else if (!string.IsNullOrEmpty (result.PostId))
{
Debug.Log (result.PostId);
}
else
{
Debug.Log ("Share success");
}
}
}
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
public class Facebookmanager : MonoBehaviour {
//--------- login----------
void Awake()
{
if (!FB.IsInitialized)
{
FB.Init ();
}
else
{
FB.ActivateApp ();
}
}
public void LogIn()
{
FB.LogInWithReadPermissions (callback: OnLogIn);
}
void OnLogIn(ILoginResult result)
{
if (FB.IsLoggedIn)
{
AccessToken token = AccessToken.CurrentAccessToken;
}
else
{
Debug.Log("Canceled Login");
}
}
//------- login end-----------
//-----sharing start-------
public void Share()
{
FB.ShareLink (
contentTitle: "Mad Drift! Love this game!",
contentURL: new System.Uri ("https://yourlinkwhateveryoushare"),
contentDescription: "Mad Drift! Love this game! Download it rate it",
photoURL: new System.Uri ("https://photourl"),
callback: OnShare);
}
void OnShare (IShareResult result)
{
if (result.Cancelled || !string.IsNullOrEmpty (result.Error))
{
Debug.Log ("ShareLinkError: " + result.Error);
}
else if (!string.IsNullOrEmpty (result.PostId))
{
Debug.Log (result.PostId);
}
else
{
Debug.Log ("Share success");
}
}
}
No comments:
Post a Comment