开发者

I am trying to load a facebook profile picture with Loader()

I'm hav开发者_Python百科ing 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.


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜