我正在尝试使用 Loader() 加载 Facebook 个人资料图片

发布于 2024-10-20 10:05:36 字数 2880 浏览 1 评论 0原文

我在将用户 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相对绾红妆 2024-10-27 10:05:36

该行

debug.appendText(" \n" + loader.content);

出现在 Event.COMPLETE 处理程序之外。

我会为 open、progress 和 httpStatus 事件添加更多侦听器。 httpStatus 事件应该非常有帮助。

您可以在 facebookProxy.php 中添加一些调试吗?

The line

debug.appendText(" \n" + loader.content);

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?

遇到 2024-10-27 10:05:36

我能够弄清楚这一点。 Variables.path 和 request.data 以及 facebookProxy.php 根本没有必要。

更改为“删除”后

var request:URLRequest = new URLRequest("facebookProxy.php");

允许

var request:URLRequest = new URLRequest(Facebook.getImageUrl(Facebook.getSession().uid, large));
loader.load(request);
picturePlaceHolder.addChild(loader);

图片

var variables:URLVariables = new URLVariables();
variables.path = Facebook.getImageUrl(Facebook.getSession().uid);
request.data = variables;

正确加载。很难找到所有这些内容的最新教程,为什么呢?但我想我必须提出一个新问题才能找到答案,哈哈。

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

var request:URLRequest = new URLRequest("facebookProxy.php");

to

var request:URLRequest = new URLRequest(Facebook.getImageUrl(Facebook.getSession().uid, large));
loader.load(request);
picturePlaceHolder.addChild(loader);

Removing

var variables:URLVariables = new URLVariables();
variables.path = Facebook.getImageUrl(Facebook.getSession().uid);
request.data = variables;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文