使用 Facebook Graph Api 上传 BitmapData
我一直在互联网上查找如何使用 Facebook 在其 Graph Api 中提供的 PostRequest 类,但我找不到任何内容。我想知道如何使用它来上传位图数据。它看起来根本就没有动。
我使用了这段代码并且它起作用了:
private function getSnapshot(e:MouseEvent):void
{
bmd = new BitmapData(vidDisplay.width, vidDisplay.height);
bmd.draw(vidDisplay);
vidDisplay.previewImg.source = new Bitmap(bmd);
isSnapshot = true;
vidDisplay.upload_btn.enabled = true;
vidDisplay.caption_txt.enabled = true;
vidDisplay.browse_btn.enabled = false;
}
protected function upload(w:MouseEvent):void
{
var img:* = (isSnapshot) ? bmd : fileRef ;
var values:Object = {message:vidDisplay.caption_txt.text, fileName:'FILE_NAME', image:img};
fb.callApi("post", "me", "photos", values);
vidDisplay.caption_txt.text = "";
vidDisplay.upload_btn.enabled = false;
vidDisplay.snapShot_btn.enabled = false;
}
但是,当我尝试制作一个完整的函数来拍照并立即上传时,它不起作用。起初是这样的:
private function doTakeSnapshot(con:MovieClip, cap:String = null):void
{
ExternalInterface.call("doAlert", "doTakeSnapshot");
var bmd:BitmapData = new BitmapData(con.width, con.height);
bmd.draw(con);
if (cap == null) { cap = "Check out my photo!"; }
var values:Object = {message:cap, image:bmd};
doCallApi("post", "me", "photos", values);
}
然后我尝试使用PostRequest:
private function doTakeSnapshot(con:MovieClip, cap:String = null):void
{
ExternalInterface.call("doAlert", "doTakeSnapshot");
var bmd:BitmapData = new BitmapData(con.width, con.height);
bmd.draw(con);
if (cap == null) { cap = "Check out my photo!"; }
var ba:ByteArray = PNGEncoder.encode(bmd);
var pr:PostRequest = new PostRequest();
//var ba:ByteArray = pr.getPostData();
pr.createPostData();
pr.writePostData("fileName", "testtest");
pr.writeFileData("fileName", ba, "image/png");
pr.close();
var byteArray:ByteArray = pr.getPostData();
ExternalInterface.call("doAlert", "ByteArray = " + byteArray);
var values:Object = {message:cap, image:byteArray};
doCallApi("post", "me", "photos", values);
}
两者都不起作用,这让我很困惑。第一个在没有以任何方式编码的情况下工作,所以我不明白为什么当我尝试这样调用它时它不起作用。有什么帮助吗?
I've been looking around the internet on how to use the PostRequest class given by the Facebook in their Graph Api, but I couldn't find anything on it. I'm wondering how to use it to upload a bitmapdata. It just doesn't seem to be moving at all.
I used this code and it worked:
private function getSnapshot(e:MouseEvent):void
{
bmd = new BitmapData(vidDisplay.width, vidDisplay.height);
bmd.draw(vidDisplay);
vidDisplay.previewImg.source = new Bitmap(bmd);
isSnapshot = true;
vidDisplay.upload_btn.enabled = true;
vidDisplay.caption_txt.enabled = true;
vidDisplay.browse_btn.enabled = false;
}
protected function upload(w:MouseEvent):void
{
var img:* = (isSnapshot) ? bmd : fileRef ;
var values:Object = {message:vidDisplay.caption_txt.text, fileName:'FILE_NAME', image:img};
fb.callApi("post", "me", "photos", values);
vidDisplay.caption_txt.text = "";
vidDisplay.upload_btn.enabled = false;
vidDisplay.snapShot_btn.enabled = false;
}
However, when I tried to make a whole function to take a picture and upload straightaway, it doesn't work. At first, it was like this:
private function doTakeSnapshot(con:MovieClip, cap:String = null):void
{
ExternalInterface.call("doAlert", "doTakeSnapshot");
var bmd:BitmapData = new BitmapData(con.width, con.height);
bmd.draw(con);
if (cap == null) { cap = "Check out my photo!"; }
var values:Object = {message:cap, image:bmd};
doCallApi("post", "me", "photos", values);
}
Then I tried with the PostRequest:
private function doTakeSnapshot(con:MovieClip, cap:String = null):void
{
ExternalInterface.call("doAlert", "doTakeSnapshot");
var bmd:BitmapData = new BitmapData(con.width, con.height);
bmd.draw(con);
if (cap == null) { cap = "Check out my photo!"; }
var ba:ByteArray = PNGEncoder.encode(bmd);
var pr:PostRequest = new PostRequest();
//var ba:ByteArray = pr.getPostData();
pr.createPostData();
pr.writePostData("fileName", "testtest");
pr.writeFileData("fileName", ba, "image/png");
pr.close();
var byteArray:ByteArray = pr.getPostData();
ExternalInterface.call("doAlert", "ByteArray = " + byteArray);
var values:Object = {message:cap, image:byteArray};
doCallApi("post", "me", "photos", values);
}
Both doesn't work, which puzzles me. The first one worked without encoding it in any way, so I don't get why it doesn't work when I try to just call it like that. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必包装或编码您的位图数据。只需制作一个位图并将其放入您的对象中,如下所示:
You don't have to wrap or encode your bitmapdata. Just make a Bitmap and put it in your object like this :