Android Unity Facebook SDK:FB.Feed未发布

Android Unity Facebook SDK:FB.Feed未发布,android,facebook,unity3d,facebook-unity-sdk,Android,Facebook,Unity3d,Facebook Unity Sdk,我完成了比赛。现在我想让它社交化。在twitter上发帖很容易,但我对facebook有一个问题 我在FacebookDev上创建了一个应用程序,我有密钥散列,密钥存储,我在控制台中没有任何错误。我创建了带有JDK和OpenSSL路径的环境变量。 也许我的代码有问题(来自SDK示例),但我不知道是什么 此脚本附加到NGUI按钮。在编辑器中它可以工作,但在设备上它只要求登录和权限。然后什么也没发生 using UnityEngine; using System; using System.Coll

我完成了比赛。现在我想让它社交化。在twitter上发帖很容易,但我对facebook有一个问题

我在FacebookDev上创建了一个应用程序,我有密钥散列,密钥存储,我在控制台中没有任何错误。我创建了带有JDK和OpenSSL路径的环境变量。 也许我的代码有问题(来自SDK示例),但我不知道是什么

此脚本附加到NGUI按钮。在编辑器中它可以工作,但在设备上它只要求登录和权限。然后什么也没发生

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();
}
使用UnityEngine;
使用制度;
使用系统集合;
使用System.Collections.Generic;
使用System.Linq;
公共密封类FacebookShare:MonoBehavior{
#region FB.Init()示例
private bool isInit=false;
无效唤醒()
{
CallFBInit();
}
私有void CallFBInit()
{
FB.Init(OnInitComplete,OnHideUnity);
}
私有void OnInitComplete()
{
Debug.Log(“FB.Init完成:用户是否登录?”+FB.IsLoggedIn);
isInit=true;
}
私密的虚空隐藏(如图所示)
{
Log(“正在播放游戏吗?”+正在播放游戏);
}
#端区
#region FB.Login()示例
私有void CallFBLogin()
{
FB.登录(“电子邮件、发布操作”,LoginCallback);
}
void LoginCallback(FBResult结果)
{
if(result.Error!=null)
lastResponse=“错误响应:\n”+结果。错误;
如果(!FB.IsLoggedIn)为else,则为
{
lastResponse=“玩家取消登录”;
}
其他的
{
lastResponse=“登录成功!”;
}
}
私有void CallFBLogout()
{
FB.Logout();
}
#端区
#region FB.Feed()示例
公共字符串FeedToId=“”;
公共字符串FeedLink=“”;
公共字符串FeedLinkName=“”;
公共字符串FeedLinkCaption=“”;
公共字符串FeedLinkDescription=“”;
公共字符串FeedPicture=“”;
公共字符串FeedMediaSource=“”;
公共字符串FeedActionName=“”;
公共字符串FeedActionLink=“”;
公共字符串FeedReference=“”;
public bool IncludeFeedProperties=false;
私有字典FeedProperties=新字典();
私有void CallFBFeed()
{
Dictionary feedProperties=null;
if(IncludeFeedProperties)
{
feedProperties=feedProperties;
}
饲料(
toId:FeedToId,
链接:FeedLink,
linkName:FeedLinkName,
linkCaption:FeedLinkCaption,
linkDescription:FeedLinkDescription,
图片:FeedPicture,
mediaSource:FeedMediaSource,
actionName:FeedActionName,
actionLink:FeedActionLink,
参考:FeedReference,
属性:feedProperties,
回调:回调
);
}
#端区
公共字符串ApiQuery=“”;
私有字符串lastResponse=“”;
私有纹理2D lastResponseTexture;
无效回调(FBResult结果)
{
lastResponseTexture=null;
//有些平台返回空字符串而不是null。
如果(!String.IsNullOrEmpty(result.Error))
lastResponse=“错误响应:\n”+结果。错误;
如果(!ApiQuery.Contains(“/picture”),则为else
lastResponse=“成功响应:\n”+结果.Text;
其他的
{
lastResponseTexture=result.Texture;
lastResponse=“成功响应:\n”;
}
}
void OnClick()
{
CallFBLogin();
CallFBFeed();
}

}

在调用LoginCallback之前,您正在尝试馈送。尝试更改LoginCallback和OnClick函数,如下所示:

   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!";
            CallFBFeed();
        }
    }
    void OnClick ()
    {
       CallFBLogin();
    }

这没用。现在它在编辑器中也不起作用了(我认为它只是第一次起作用)。也许是跟keyhash有关?现在它使用debug.keystore。也许我应该使用我在游戏中创建的密钥库中的密钥散列?很抱歉稍后的回复。是的,您必须在facebook开发者控制台上的应用程序设置选项卡的“Android/密钥哈希”字段中放入调试密钥哈希。然后别忘了对发布密钥执行此操作。您是否尝试过运行SDK中内置的“InteractiveConsole”示例场景?(还有,正如下面提到的@sat,你必须等到登录成功后才能调用fb提要)。@aaron是的,我试过了,它在编辑器中工作得很好,但在设备上它只要求登录和许可。然后什么也没发生。你能发布一个日志文件,记录你尝试运行时发生的情况吗?另外,我们刚刚发布了一个新的v6 SDK:如果您不在该版本上,也许可以试一试。@aaron我安装了新的SDK,但没有帮助。”这是登录后发生的事情。@aaron哦,好像我犯了一个非常愚蠢的错误:)我以为“Feed to Id”应该是应用程序Id。我把它留空了,现在它可以工作了!无论如何,谢谢你的帮助。