简体   繁体   English

Unity Facebook SDK:FB.Feed不发布

[英]Unity Facebook SDK: FB.Feed not posting

I finished my game. 我完成了比赛。 Now I want to make it social. 现在,我想使其变得社交化。 Posting to twitter is easy, but I have a problem with facebook. 发布到Twitter很容易,但是我对Facebook有问题。

I created an app on facebook dev, I have key-hash, key-store, I don't have any errors in console. 我在facebook dev上创建了一个应用,我有密钥哈希,密钥存储,控制台没有任何错误。 I made enviroment variables with paths to JDK and OpenSSL. 我使用指向JDK和OpenSSL的路径制作了环境变量。 Maybe there's something wrong with my code (it's from SDK example) but I don't know what. 我的代码也许有问题(来自SDK示例),但我不知道是什么。

This script is attached to NGUI button. 该脚本已附加到NGUI按钮。 In editor it works but on device it only asks to login and permission. 在编辑器中,它可以工作,但在设备上,它仅要求登录和许可。 Then nothing happens. 然后什么也没有发生。

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();
}

} }

You trying to feed before LoginCallback called. 您试图在LoginCallback调用之前进行订阅。 Try to change your LoginCallback and OnClick functions something like this: 尝试更改您的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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM