4

我正在开发一个统一游戏,您可以拍摄照片并将这张照片上传到Facebook,并附上一些标签和内容(非常像friendsmash)。问题是我没有可以放置屏幕截图的网络服务器,而Fb.Feeb(图片:)属性只接受网址。将图片从统一上传到Facebook

我读过,您可以使用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

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

+0

有什么方法可以添加标题/预定义的文字或描述吗? – Imran

+0

不是我已经找到,对不起 – Reaver

+0

@Imran相信你可以:wwwForm.AddField(“message”,“Your message here”); wwwForm.AddField(“description”,“你的描述在这里”); –