Hi!
I finished my game. Now I want to make it social.
Posting to twitter is easy, but I have problem with facebook.
I created an app on facebook dev, I have key-hash, key-store, I don’t have any errors in console. I made enviroment variables with paths to JDK and OpenSSL.
I think that there’s something wrong with my code (it’s from SDK example) but I don’t know what.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public sealed class FacebookShare : MonoBehaviour {
#region FB.Init() example
private bool isInit = false;
void Awake ()
{
CallFBInit();
}
private void CallFBInit()
{
FB.Init(OnInitComplete, OnHideUnity);
}
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
isInit = true;
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
#endregion
#region FB.Login() example
private void CallFBLogin()
{
FB.Login("email,publish_actions", LoginCallback);
}
void LoginCallback(FBResult result)
{
if (result.Error != null)
lastResponse = "Error Response:
" + result.Error;
else if (!FB.IsLoggedIn)
{
lastResponse = “Login cancelled by Player”;
}
else
{
lastResponse = “Login was successful!”;
}
}
private void CallFBLogout()
{
FB.Logout();
}
#endregion
#region FB.Feed() example
public string FeedToId = "";
public string FeedLink = "";
public string FeedLinkName = "";
public string FeedLinkCaption = "";
public string FeedLinkDescription = "";
public string FeedPicture = "";
public string FeedMediaSource = "";
public string FeedActionName = "";
public string FeedActionLink = "";
public string FeedReference = "";
public bool IncludeFeedProperties = false;
private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
private void CallFBFeed()
{
Dictionary<string, string[]> feedProperties = null;
if (IncludeFeedProperties)
{
feedProperties = FeedProperties;
}
FB.Feed(
toId: FeedToId,
link: FeedLink,
linkName: FeedLinkName,
linkCaption: FeedLinkCaption,
linkDescription: FeedLinkDescription,
picture: FeedPicture,
mediaSource: FeedMediaSource,
actionName: FeedActionName,
actionLink: FeedActionLink,
reference: FeedReference,
properties: feedProperties,
callback: Callback
);
}
#endregion
public string ApiQuery = "";
private string lastResponse = "";
private Texture2D lastResponseTexture;
void Callback(FBResult result)
{
lastResponseTexture = null;
// Some platforms return the empty string instead of null.
if (!String.IsNullOrEmpty(result.Error))
lastResponse = "Error Response:
" + result.Error;
else if (!ApiQuery.Contains(“/picture”))
lastResponse = "Success Response:
" + result.Text;
else
{
lastResponseTexture = result.Texture;
lastResponse = "Success Response:
";
}
}
void OnClick ()
{
CallFBLogin();
CallFBFeed();
}
}
This script is attached to NGUI button.
In editor it works but on device it only asks to login and permision. Then nothing happens.