其他分享
首页 > 其他分享> > android – 从Unity上传图片到facebook

android – 从Unity上传图片到facebook

作者:互联网

我在团结游戏中工作,你可以拍照并将这张照片上传到facebook,以及一些标签和东西(很像friendsmash).问题是我没有可以放屏幕截图的网络服务器,而且Fb.Feeb(picture :)属性只接受网址.

我已经读过你可以使用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());
}

解决方法:

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

标签:android,facebook,unity3d,facebook-unity-sdk,facebook-sdk-3-0
来源: https://codeday.me/bug/20190624/1281229.html