Unity Facebook SDK:FB.Feed没有发布

时间:2014-08-02 12:19:23

标签: android facebook unity3d facebook-unity-sdk

我完成了比赛。现在我想让它变得社交。发布到Twitter很容易,但我的Facebook有问题。

我在facebook dev上创建了一个应用程序,我有密钥哈希,密钥库,我在控制台中没有任何错误。我使用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();
}

}

1 个答案:

答案 0 :(得分:0)

您尝试在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();
    }