- Home /
Unity Social Integration - Facebook Button Not Working?
Hi I have a game that pops up a Facebook button when the game ends so the user can share their highscore (kinda like a flappy bird simple game). The Facebook button works. Alls this does is when the button is clicked take the user to the Facebook app on their iOS device and take them directly to post area of the Facebook app and already have text they can post in their for them which is what it is doing. But in the picture below you will see that it doesn't put the text in the area i want it to (area with red circle) it puts it in that box thing? I want all that text just to be in the area marked by red?
I am not using any plugins either and please don't suggest any as I do not want to use anything beside the Unity Facebook SDK.Thanks in advance (:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class FacebookButton : MonoBehaviour {
protected string lastResponse = "";
protected Texture2D lastResponseTexture;
public GameObject currentScoreGui;
void Start () {
CallFBInit();
}
void OnMouseUp ()
{
Debug.Log("Finger lifted off Facebook button...");
if (gameObject.tag == "UIFacebook") {
CallFBLogin();
if (FB.IsLoggedIn) {
// Call feed post
CallFBFeed();
Debug.Log("Feed has been called...");
}
Debug.Log("Facebook Button Pressed...");
}
}
#region FB.Feed() example
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: "",
link: "",
linkName: "Jump Now! = linkName",
linkCaption: "Jump Now! Is such a cool game = linkCaption",
linkDescription: "I've just scored" + currentScoreGui.guiText.text + " points in #JumpNow! Download it from the @AppStore and try to beat me! https://itunes.apple.com/us/artist/john-pagley/id840382873 = linkDescription",
picture: "",
mediaSource: "",
actionName: "",
actionLink: "",
reference: "",
properties: feedProperties,
callback: Callback
);
}
#endregion
void Awake()
{
FeedProperties.Add("key1", new[] { "valueString1" });
FeedProperties.Add("key2", new[] { "valueString2", "http://www.facebook.com" });
}
#region FB.Init() example
private void CallFBInit()
{
FB.Init(OnInitComplete, OnHideUnity);
}
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + 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;
}
}
#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
protected 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 (!String.IsNullOrEmpty (result.Text))
{
lastResponse = "Success Response:\n" + result.Text;
}
else if (result.Texture != null)
{
lastResponseTexture = result.Texture;
lastResponse = "Success Response: texture\n";
}
else
{
lastResponse = "Empty Response\n";
}
}
}
Answer by digzou · Dec 22, 2014 at 02:19 PM
As far as I know you cannot "prefill" [canned text] that text box. Facebook doesnt allow you to do this according to its policies.User can only populate that text box. I had one of my android native app rejected from facebook for doing what you intend to do. How I go about now is, I prefill whatever I want to in the description and caption of the feed.
Hope this helps :)