将图片从Facebook上传到团队 [英] Upload picture to facebook from unity

查看:132
本文介绍了将图片从Facebook上传到团队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个统一的游戏,你可以拍摄照片,并将这张图片上传到Facebook与统一以及一些标签和东西(非常像friendsmash)。问题是我没有网络服务器,我可以把屏幕截图,而Fb.Feeb(图片:)属性只接受URL。

Im working on a unity game where you can take a picture and upload this picture to facebook from unity along with some tags and stuff (much like friendsmash). The problem is that i do not have a web-server that i can put the screenshots on, and the Fb.Feeb(picture:) attribute only accepts urls.

我已经读过,你可以使用HTTP POST将图片发布给用户的图片,然后使用图片中的链接,但我不知道任何关于HTTP POST,我不知道如何做到。

I have read that you can use HTTP POST to post the picture to the users images and then use that link in picture:, but i dont know anything about HTTP POST and i couldnt figure out how to do it.

我也读过,你可以使用FB.API()以某种方式做到这一点,但我无法理解。

I have also read that you can use FB.API() to somehow do this, but i couldnt figure it out.

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

Any sample code would be greatly appreciated.

我目前的代码:

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


推荐答案

Facebook sdk确实有所有这些都是这样做的。你需要使用Fb.API()。
这是为我工作的方式:

The facebook sdk does have a way to make this happen after all. You need to use Fb.API(). This is the way it worked for me:

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

一般来说,添加一些标题,就是这样。 ..

In general terms, to add some sort of caption, it's along the lines...

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记录的字典字段似乎不起作用,所以先尝试消息。

The key field seems to be "message". Confusingly, the "dictionary" field documented by FB, seems to just not work, so try "message" at first.

这篇关于将图片从Facebook上传到团队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆