我正在尝试使用 Loader() 加载 Facebook 个人资料图片
我在将用户 facebook 个人资料图片的 url 传递给 Loader() 变量时遇到问题。我正在使用 PHP 文件来绕过安全性,从我所做的调试来看,它表明我得到的 URL 很好,但加载器运行错误事件侦听器。这是我的 facebookProxy.php 文件的样子;
<?php
$path=$_GET['path'];
header("Content-Description: Facebook Proxied File");
header("Content-Type: image");
header("Content-Disposition: attactment; filename =".$path);
@readfile($path);
?>
这是我加载 url 然后加载图像的代码。
function LoadMyPicture():void
{
debug.text = "Entered loadMyPicture() function";
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, MyPictureLoaded, false, 0, true);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError, false, 0, true);
var request:URLRequest = new URLRequest("facebookProxy.php");
var variables:URLVariables = new URLVariables();
variables.path = Facebook.getImageUrl(Facebook.getSession().uid);
request.data = variables;
loader.load(request);
addChild(loader);
debug.appendText(" \nURLRequest url: " + request.url);
debug.appendText(" \nURLRequest data: " + request.data);
debug.appendText(" \n" + loader.content);
}
function MyPictureLoaded(e:Event):void
{
debug.appendText(" \nEntering MyPictureLoaded");
var loader:Loader = e.target.loader;
var bitmap = Bitmap(loader.content);
bitmap.smoothing = true;
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, MyPictureLoaded);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError);
debug.appendText(" \nLoader Content: " + loader.content);
//Note: picturePlaceholder is just a blank movie clip on the Stage
bitmap.width = picturePlaceHolder.width;
bitmap.height = picturePlaceHolder.height;
picturePlaceHolder.addChild(bitmap);
debug.appendText(" \nBitmap width: " + String(bitmap.width) +
" \nBitmap height: " + String(bitmap.height))
}
function MyPictureLoadError(e:Event):void
{
debug.appendText(" \nMyPictureLoadError: Loader Error!");
}
debug.appendText(" \nURLRequest url: " + request.url);
debug.appendText(" \nURLRequest data: " + request.data);
调试.appendText(" \n" + loader.content);
这些行显示如下;
URLRequest url:facebookProxy.php
URLRequest 数据:path=https%3A%2F%2Fgraph%2Efacebook%2Ecom%2F100001902730917%2Fpicture
null
所以加载器中的内容为空,我该如何调试?有人有任何解决方案可以帮助我吗?
编辑
我忘了提及,我遵循了一个教程,该教程没有解释他们提供的代码的任何基础知识,所以我对加载器的概念相当迷失。这是我遵循的教程 使用开放图形 API 将 Facebook 个人资料图片加载到 Flash SWF。
I'm having trouble passing the url for a users facebook profile picture to a Loader() variable. I'm using a PHP file to get around the security and from the debug I made, it shows that I'm getting the URL fine, but the Loader runs the error event listener. Here is what my facebookProxy.php file looks like;
<?php
$path=$_GET['path'];
header("Content-Description: Facebook Proxied File");
header("Content-Type: image");
header("Content-Disposition: attactment; filename =".$path);
@readfile($path);
?>
and here is my code for loading the url then loading the image.
function LoadMyPicture():void
{
debug.text = "Entered loadMyPicture() function";
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, MyPictureLoaded, false, 0, true);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError, false, 0, true);
var request:URLRequest = new URLRequest("facebookProxy.php");
var variables:URLVariables = new URLVariables();
variables.path = Facebook.getImageUrl(Facebook.getSession().uid);
request.data = variables;
loader.load(request);
addChild(loader);
debug.appendText(" \nURLRequest url: " + request.url);
debug.appendText(" \nURLRequest data: " + request.data);
debug.appendText(" \n" + loader.content);
}
function MyPictureLoaded(e:Event):void
{
debug.appendText(" \nEntering MyPictureLoaded");
var loader:Loader = e.target.loader;
var bitmap = Bitmap(loader.content);
bitmap.smoothing = true;
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, MyPictureLoaded);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError);
debug.appendText(" \nLoader Content: " + loader.content);
//Note: picturePlaceholder is just a blank movie clip on the Stage
bitmap.width = picturePlaceHolder.width;
bitmap.height = picturePlaceHolder.height;
picturePlaceHolder.addChild(bitmap);
debug.appendText(" \nBitmap width: " + String(bitmap.width) +
" \nBitmap height: " + String(bitmap.height))
}
function MyPictureLoadError(e:Event):void
{
debug.appendText(" \nMyPictureLoadError: Loader Error!");
}
debug.appendText(" \nURLRequest url: " + request.url);
debug.appendText(" \nURLRequest data: " + request.data);
debug.appendText(" \n" + loader.content);
These lines show as follows;
URLRequest url: facebookProxy.php
URLRequest data: path=https%3A%2F%2Fgraph%2Efacebook%2Ecom%2F100001902730917%2Fpicture
null
So the content in the loader is null, how would I debug this? Does anyone have any solutions that could help me?
EDIT
I forgot to mention that I followed a tutorial to that did not explain any of the basics about the code that they provided, so I'm fairly lost to the concept of the loader. This is the tutorial I followed Loading Facebook profile picture into Flash SWF using open graph api.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该行
出现在 Event.COMPLETE 处理程序之外。
我会为 open、progress 和 httpStatus 事件添加更多侦听器。 httpStatus 事件应该非常有帮助。
您可以在 facebookProxy.php 中添加一些调试吗?
The line
occurs outside of the Event.COMPLETE handler.
I would add more listeners for the open, progress, and httpStatus events. The httpStatus event should be very helpful.
Can you add some debugging in your facebookProxy.php?
我能够弄清楚这一点。 Variables.path 和 request.data 以及 facebookProxy.php 根本没有必要。
更改为“删除”后
允许
图片
正确加载。很难找到所有这些内容的最新教程,为什么呢?但我想我必须提出一个新问题才能找到答案,哈哈。
I was able to figure this out. The variables.path and request.data together with the facebookProxy.php wasn't necessary at all.
After changing the
to
Removing
Allowed the picture to load properly. It's hard to find an up to date tutorial for all of this, why is that? but I guess I would have to open up a new question to find out lol.