- Home /
Facebook SDK: FB.Feed not posting
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:\n" + 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:\n" + result.Error;
else if (!ApiQuery.Contains("/picture"))
lastResponse = "Success Response:\n" + result.Text;
else
{
lastResponseTexture = result.Texture;
lastResponse = "Success Response:\n";
}
}
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.
$$anonymous$$eyHash in Fb settings is the same key of Debug_Android_$$anonymous$$ey_Hash? If yes, then fb.feed should not work...
Answer by Kiwasi · Aug 12, 2014 at 10:43 AM
Often Facebook code problems are on the Facebook side. Do you have publish_actions on the token you are using? Try run the token though the Facebook debugger. If the token does not have the request actions then you can get a more permissive one using the open graph explorer.
For other people to use publish_actions you must have completed facebooks submission and review process.
Answer by darkmwar · Aug 15, 2014 at 04:58 PM
publish_actions
gave me errors when I logcat in adb. try basic_info
as permission.