我在Unity工作。
我尝试使用Facebook SDK插件将分数发布到Facebook墙上。
虽然我使用了安装了官方Facebook应用程序的设备(Nexus7,MotoG),FB.Feed()
方法无效,对话框也没有出现在设备中。
我在Facebook Unity SDK on Android - Login fails when FB App installed上尝试了解决方案,但它对我不起作用。
这是我的fblogin
脚本:
public class fblogin : MonoBehaviour
{
private string status = "Ready";
private string lastResponse = "";
public GUIStyle textStyle = new GUIStyle ();
private Texture2D lastResponseTexture;
private bool isInit = false;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnGUI ()
{
if (GUI.Button (new Rect (10, 10, 300, 100), "FB.Init")) {
CallFBInit ();
status = "FB.Init() called with " + FB.AppId;
}
if (GUI.Button (new Rect (100, 100, 300, 100), "Login")) {
//FB.Init (OnInitComplete, OnHideUnity);
//status = "FB.Init() called with " + FB.AppId;
CallFBLogin ();
}
if (GUI.Button (new Rect (200, 200, 300, 100), "Share")) {
//FB.Init (OnInitComplete, OnHideUnity);
//status = "FB.Init() called with " + FB.AppId;
onBragClicked ();
}
}
private void onBragClicked ()
{
//Util.Log ("onBragClicked");
FB.Feed (
linkCaption: "I just smashed " + "15" + " friends! Can you beat it?",
picture: "http://www.friendsmash.com/images/logo_large.jpg",
linkName: "Checkout my Friend Smash greatness!",
link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
);
}
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);
}
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!";
}
}
}
有人可以帮忙吗?
答案 0 :(得分:1)
将这个放入你的脚本中并在检查器中填写所有的FeedParameters,我认为这是因为你没有在你的feed中指定回调,而是将它放在你的脚本中并在检查器中填写参数,其中一些是feilds是必需的,否则饲料甚至不会出现
#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[]>();
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";
//}
}
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