- Home /
Facebook Post to wall FB.Feed issue in Unity Facebook SDK
I have an issue with the 'post to wall' functionality of the SDK. I have a very simple game, and the posts to the wall works. However, there's a couple problems.
1) I get TWO dialogs with this current code. One that says "post to timeline", which has all the relevant info in the CallFBFeed method, and then once you post, you get a second dialog, and the only differences is in the design of the dialog, and the title which is "Post to Wall".
2) The first dialog is overlaying the game, and the game is still accepting clicks right through the dialog. The second dialog grays the game (the whole browser window actually) and allows you to click anywhere but only accepts clicks in the dialog.
I want the functionality of #2, but only #2. What am I doing wrong?
public class FacebookManager : MonoBehaviour {
public bool isInit = false;
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 string status = "Ready";
private string lastResponse = "";
private Texture2D lastResponseTexture;
public string ApiQuery = "";
public static FacebookManager use;
void Start(){
use = this;
}
public void PostToFacebook(){
if(GameManager.use.soundEffectsOn) GameManager.use.GUIAudio.audio.Play();
if(isInit) {
CallFBFeed ();
}
else{
CallFBLogin ();
}
}
public void CallFBInit()
{
FB.Init(OnInitComplete, OnHideUnity);
}
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
isInit = true;
//FB Initialized. Let's login if we're not.
//if(!FB.IsLoggedIn) CallFBLogin();
}
private void OnHideUnity(bool isGameShown)
{
FbDebug.Log("OnHideUnity");
if (!isGameShown)
{
// pause the game - we will need to hide
Time.timeScale = 0;
}
else
{
// start the game back up - we're getting focus again
Time.timeScale = 1;
}
}
private void CallFBLogin()
{
FB.Login("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 if(FB.IsLoggedIn){
//Logged in successfully. Let's post a story.
CallFBFeed();
}
}
private void CallFBLogout()
{
FB.Logout();
}
private void CallFBFeed()
{
Dictionary<string, string[]> feedProperties = null;
if (IncludeFeedProperties)
{
feedProperties = FeedProperties;
}
FB.Feed(
toId: FeedToId,
link: "placeholder",
linkName: "placeholder",
linkCaption: "placeholder",
linkDescription: "placeholder",
picture: "placeholder",
mediaSource: FeedMediaSource,
actionName: "placeholder",
actionLink: "placeholder",
reference: FeedReference,
properties: feedProperties,
callback: Callback
);
}
void Callback(FBResult result)
{
lastResponseTexture = null;
if (result.Error != null)
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";
}
}
Answer by Belial · Apr 29, 2014 at 04:06 PM
It looks like you're calling CallFBFeed() twice, here:
public void PostToFacebook(){
if(GameManager.use.soundEffectsOn) GameManager.use.GUIAudio.audio.Play();
if(isInit) {
CallFBFeed ();
}
else{
CallFBLogin ();
}
}
And here:
void LoginCallback(FBResult result)
{
if (result.Error != null)
lastResponse = "Error Response:\n" + result.Error;
else if (!FB.IsLoggedIn) {
lastResponse = "Login cancelled by Player";
} else if(FB.IsLoggedIn){
//Logged in successfully. Let's post a story.
CallFBFeed();
}
}
I'd suggest getting rid of the first one, you'd want to get the dialog to pop up after logging in, not after initializing the SDK.
hi, did you solve the problem? i was trying a few days FB.Feed but i can't submit the post using ios, only works on the inspector
Your answer
Follow this Question
Related Questions
FB.Apprequest problem 0 Answers
Facebook Developer Alert: Recent API calls to Graph API v2.0 2 Answers
"Facebook object not loaded yet" error 3 Answers
Facebook SDK web player FB.init problem 2 Answers