上传图片从Facebook的统一 [英] Upload picture to facebook from unity

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

问题描述

进出口工作在一个统一的游戏,你可以拍摄照片和团结的一些标签和东西(很像friendsmash)一起上传这张照片到Facebook。问题是,我没有一个Web服务器,我可以把截图和Fb.Feeb(图片:)属性只接受的URL。

我已阅读,您可以使用HTTP POST将图片张贴到用户的图像,然后使用该图片链接:,但我不知道有关HTTP POST任何事情,我不能弄清楚如何做到这一点。

我也看过,你可以用FB.API()以某种方式做到这一点,但我不能看着办吧。

任何样品code将大大AP preciated。

我目前的code:

 私人字符串_path =文件://+ System.IO.Path.Combine(Application.persistentDataPath,图像/ image.png);无效的start()
    {
        如果(!FB.IsLoggedIn)
            FB.Login(电子邮件,publish_actions,publish_stream,user_photos,LoginCallback);
        StartCamera();
    }
私人无效OnBragClicked(){
    FbDebug.Log(OnBragClicked);//邮报(); < - 不知道如何FB.Feed(
    linkCaption:#hashtag
    图片:???,
    LINKNAME:我现在hashtaging!
    链接:https://apps.facebook.com/+ FB.AppId +?/ challenge_brag =+(?FB.IsLoggedIn FB.UserId:客人)
    );
}
 无效TakeSnapshot(){
    _snap =新的Texture2D(_webCamTexture.width,_webCamTexture.height);
    _snap.SetPixels(_webCamTexture.GetPixels());
    _snap.Apply();//System.IO.File.WriteAllBytes(_path,_snap.En codeToPNG());
}


解决方案

Facebook的SDK确实有办法让这毕竟发生。您需要使用Fb.API()。
这是它为我工作的方式:

 私人无效TakeScreenshot()
{
    VAR卡=新的Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,FALSE);
    snap.ReadPixels(新的Rect(0,0,Screen.width,Screen.height),0,0);
    snap.Apply();
    VAR截图= snap.En codeToPNG();    VAR wwwForm =新WWWForm();
    wwwForm.AddBinaryData(形象,截图,barcrawling.png);    FB.API(ME /照片,HttpMethod.POST,LogCallback,wwwForm);
}

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.

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.

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.

My current code:

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

解决方案

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

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

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