60day Posted February 3, 2009 Share Posted February 3, 2009 We have a flash app that reads in 6 random user friends from facebook. It takes in the friend's ID, friend's name, and URL to the friend's profile pic. We're using PHP to generate the random friends but we're having one problem. If you log in to facebook and go to our application, the application launches but the images do not appear in the application. Instead you get this error from the flash app: TypeError: Error #2007: Parameter url must be non-null. However, if you first put the http call (http://mysite.com/info.php) to the PHP file on our server into the browser you are then asked to log in to facebook and the correct query string appears in the browser. If you subsequently go to our application, the images load properly and everything works. Below is the actonscript 3 code we're using to call the php file and read in the result to an array. As you can see there is a call in the flash code to mysite.com/info.php. There is also code for two php files. The first is for info.php and the second is for the php file it calls to pull 6 random friends. We're new to both actionscript and php. any idea why it would work after first going to http://mysite.com/php (which forces you to login to facebook) and then launching the app but not work if clear your cahce, log in to facebook, and launch the app even thought the app calls http://mysite.com/php? Flash code: stop(); import flash.system.LoaderContext; var startPage:Startpage; getFriends(); //reads in the id, username, and picture from a file for the enemies //also sets the enemey kill count to 0 function getFriends() { //telling the loader that we are dealing with variables here. loader.dataFormat=URLLoaderDataFormat.VARIABLES; //we listen for the even called COMPLETE which means it will active //a function called "loading" when our flash movie has completed loader.addEventListener(Event.COMPLETE, loading); //Here we tell our loading which file to extract from. loader.load(new URLRequest("http://mysite.com/info.php")); //This is the function that will happen when the eventlistener activates. function loading(event:Event):void { for (var i = 0; i<6; i++) { friendsArray[i]=new Array ; for (var j = 0; j < 4; j++) { if (j==0) { friendsArray[i][j]=event.target.data["invader"+i+"_uid"]; } else if (j == 1) { friendsArray[i][j]=event.target.data["invader"+i+"_name"]; } else if (j == 2) { var content1:LoaderContext = new LoaderContext(); content1.checkPolicyFile = true; var loader2:Loader = new Loader(); var request:URLRequest=new URLRequest(event.target.data["invader"+i+"_pic"]); loader2.load(request, content1); //stores the loader2 sprite in the array friendsArray[i][j]=loader2; } else if (j == 3) { friendsArray[i][j]=0; } } } startPage = new Startpage; addChild(startPage); btnPlay.addEventListener(MouseEvent.CLICK, playGame); } } function playGame(event:MouseEvent):void { startPage.deleteStartpage(); btnPlay.removeEventListener(MouseEvent.CLICK, playGame); gotoAndStop("play"); } Info.php code: <?php session_cache_limiter ('private_no_expire, must-revalidate'); $friendsDynamic = 1; if ($friendsDynamic == 1) { require('invader_info_dynamic.php'); } else { require('invader_info_hardcoded.php'); } ?> invader_info_dynamic.php Code: <?php require('includes/facebook/facebook.php'); define('BASE_PATH', '/home/z0day0/public_html/fb/inv/'); define('FACEBOOK_API_KEY', '12345678'); define('FACEBOOK_SECRET', '12345678'); define('FACEBOOK_CALLBACK_URL', 'http://mysite.com/inv/'); define('FACEBOOK_CANVAS_URL', 'http://apps.facebook.com/fnvaders/'); $facebook = new Facebook(FACEBOOK_API_KEY, FACEBOOK_SECRET); $uid = $facebook->require_login(); //$uid = $facebook->get_loggedin_user(); //if (!$uid) { // echo "Error Getting Firends list"; //} else { // echo $uid; //} // catch the exception that gets thrown if the cookie has an invalid session_key in it try { if (!$facebook->api_client->users_isAppUser()) { $facebook->redirect($facebook->get_add_url()); } } catch (Exception $ex) { // this will clear cookies for your application and // redirect them to a login prompt $facebook->set_user(null, null); $facebook->redirect($appcallbackurl); die( "can not load facebook class" ); } //Retrieve the Friends List $friends = $facebook->api_client->friends_get(); if($friends == FALSE) { die("you can't play this game because you have no friends."); } $total_friends = sizeof($friends) - 1; $invaders = array(); $i = 0; do { $x = rand(0,$total_friends); if (!in_array($friends[$x],$invaders) || $total_friends < 6) { $invaders[$i] = $friends[$x]; $i++; } } while ($i < 6); $i = 0; foreach ($invaders as $invader) { $invader_info = $facebook->api_client->users_getInfo($invader, array('name', 'pic_square')); if ($invader_info[0]['pic_square'] == "") { $invader_info[0]['pic_square'] = "http://mysite.com/images/inv_icon_75.jpg"; } if ($i <> 0) print "&"; print "invader".$i."_uid=" . $invader_info[0]['uid'] . "&"; print "invader".$i."_name=" . $invader_info[0]['name'] . "&"; print "invader".$i."_pic=" . $invader_info[0]['pic_square']; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/143540-how-to-read-in-facebook-profile-pics-to-a-flash-app-using-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.