I am trying to write a code that that can post the best score in my unity game to Facebook. Everything seems to work but nothing appears on my facebook page. My question is that am I missing something here to make it post to Facebook?
using UnityEngine;
using System.Collections;
using Facebook.Unity;
using System.Collections.Generic;
using UnityEngine.UI;
public class SharePhoto : MonoBehaviour {
//public GameObject LoginText;
void Awake()
{
// LoginText.SetActive(false);
FB.Init(SetInit, OnHideUnity);
}
void SetInit()
{
if(FB.IsLoggedIn)
{
Debug.Log("Facebook is logged in");
}
else
{
Debug.Log("Facebook is not logged in");
}
}
void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
public void GetPublicPermssion()
{
FB.LogInWithPublishPermissions (new List<string>(){"publish_actions"},AuthCallback);
}
void AuthCallback(IResult result)
{
if(result.Error != null)
{
Debug.Log(result.Error + " Could not get the permission");
}
else
{
if(FB.IsLoggedIn)
{
foreach(string perm in AccessToken.CurrentAccessToken.Permissions) {
// log each granted permission
Debug.Log(perm);
}
Debug.Log("Facebook is logged in");
int score = 10000;
var scoreData =
new Dictionary<string, string>() {{"score", score.ToString()}};
FB.API ("/me/scores", HttpMethod.POST, APICallback, scoreData);
}
else
{
Debug.Log("Facebook is not logged in");
}
}
}
void APICallback(IResult result)
{
if(result.Error != null)
{
Debug.Log(result.Error + "Failed to post the score");
}
else{
// LoginText.SetActive(true);
Debug.Log("Your score has been posted");
}
}
}