4

我正在开发一个统一游戏,您可以在其中拍照并将这张照片从统一上传到 Facebook,以及一些标签和东西(很像friendsmash)。问题是我没有可以放截图的网络服务器,而且 Fb.Feeb(picture:) 属性只接受 url。

我已经读到您可以使用 HTTP POST 将图片发布到用户图像,然后使用图片中的链接:,但我对 HTTP POST 一无所知,我不知道该怎么做。

我还读到您可以使用 FB.API() 以某种方式做到这一点,但我无法弄清楚。

任何示例代码将不胜感激。

我当前的代码:

private string _path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");

void Start ()
    {
        if (!FB.IsLoggedIn)
            FB.Login("email, publish_actions, publish_stream, user_photos", LoginCallback);
        StartCamera();
    }


private void OnBragClicked()

{
    FbDebug.Log("OnBragClicked");

//Post(); <-- dont know how

FB.Feed(
    linkCaption: "#hashtag",
    picture: "???",
    linkName: "Im hashtaging!",
    link: "https://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ?  FB.UserId : "guest")
    );
}


 void TakeSnapshot()

{
    _snap = new Texture2D(_webCamTexture.width, _webCamTexture.height);
    _snap.SetPixels(_webCamTexture.GetPixels());
    _snap.Apply();

//System.IO.File.WriteAllBytes(_path, _snap.EncodeToPNG());
}
4

1 回答 1

4

毕竟,facebook sdk 确实有办法做到这一点。您需要使用 Fb.API()。这是它为我工作的方式:

private void TakeScreenshot()
{
    var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    snap.Apply();
    var screenshot = snap.EncodeToPNG();

    var wwwForm = new WWWForm();
    wwwForm.AddBinaryData("image", screenshot, "barcrawling.png");

    FB.API("me/photos", HttpMethod.POST, LogCallback, wwwForm);
}

一般来说,要添加某种标题,它是沿着线条......

private byte[] postcardAsBytes;
string textMessage = "Play this great game at http://blah.com.";
Dictionary<string, object> d = new Dictionary<string, object>
  {
  { "message", textMessage },
  { "picture", postcardAsBytes }
  };
Facebook.instance.graphRequest(
        "me/photos", HTTPVerb.POST, d, yourCompletionHandler);
// in this example using the prime31 plugin, rather than the fb sdk

关键字段似乎是“消息”。令人困惑的是,FB 记录的“字典”字段似乎不起作用,所以首先尝试“消息”。

于 2013-11-26T15:36:53.280 回答