Adobe Facebook API calling "/me/picture" fails - actionscript-3

I'm using the official Adobe Facebook API in my Flash/AS3 application and for some reason the call the /me/picture seems to fail whereas the the call the /me/friends seems to work just fine:
This works OK:
Facebook.api('/me/friends', onFriendsLoaded );
protected function onFriendsLoaded( response:Object, fail:Object ) : void
{
// I can get the friends from the response object
}
This fails:
Facebook.api('/me/picture', onPictureLoaded );
protected function onPictureLoaded( response:Object, fail:Object ) : void
{
// Here response is null and fail is ÿØÿà
}
I'm calling both methods right after each other. What could be the problem?

The /me/picture call is actually not an api call at all. http://graph.facebook.com/me/picture is the url of the photo. You can actually set an image to that url. I am not an expert in Flash, but if you were doing this in html you would do the following:
<img src="http://graph.facebook.com/facebook_id/picture" />
This would show the users picture. Additionally, if you wanted to download the picture's bytes you would just make a normal web request. The response stream would be the image file.

Try this way
function onPictureLoaded(response:Object,fail:Object):void{
if (fail)
{
trace("Error");
}
var friends = response as Array;
var l:int = friends.length;
for (var i:int=0; i < l; i++)
{
trace("http://graph.facebook.com/" + friends[i].id + "/picture/")
}
}

Related

ProgressEvent.load is always the same as ProgressEvent.Total which causes the progress to fake

I'm trying to implement progress bar on a website.
The Problem:
ProgressEvent.load is always the same as ProgressEvent.Total which prevent the progress to show the real state of the upload. At the first second the xhr request does sent it looks like it finished but actually the server is still getting parts of the file.
JS:
My js code(the part of the progress) looks like that:
xhr.upload.onprogress = function (event) {
var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
that._onProgressItem(item, progress);
};
the property lengthComputable is true.
the event.loaded is 4354707 as the event.total which is 4354707.
C# Server Side:
public async Task<FileResultViewModel> Upload(string type)
{
string ServerUploadFoler = "...";
// Verify that this is an HTML Form file upload request
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
}
// Create a stream provider for setting up output streams
var streamProvider = new MultipartFormDataStreamProvider(ServerUploadFolder);
// Read the MIME multipart asynchronously content using the stream provider we just created.
await Request.Content.ReadAsMultipartAsync(streamProvider);
string guid = String.Empty;
if (serverUploadMoveFolder != ServerUploadFolder)
{
foreach (MultipartFileData fileData in streamProvider.FileData)
{
guid = Guid.NewGuid().ToString();
string newFileName = serverUploadMoveFolder + guid + GetExtension(uploadType);
FileInfo fi = new FileInfo(fileData.LocalFileName);
fi.MoveTo(newFileName);
}
}
// Create response
return new FileResultViewModel
{
FileName = guid
};
}
Chrome debug after 1 second of upload with a file of 4.2MB:
In fiddler after the request has completed:
My questions are:
How does the browser knows the loaded size? How does it split the file to parts and based on what params?
How do the xhr.upload.onprogress function event get updated with the progress? Does it the server which report about his progress and if it is so where is it on the code because I didn't handle it.
Why doesn't the loaded property show the real size of part?

Getting an empty Facebook news feed response using Facebook C# SDK

I am using the Facebook C# SDK in my Silverlight 4 browser app to perform some requests to the Facebook Graph API. I followed the example in the SDK documentation to request the user's information (using the asynchronous method to make it work on Silverlight):
var fb = new FacebookClient(accessToken);
fb.GetAsync("/me");
fb.GetCompleted += (o, ea) =>
{
var result = (JsonObject)ea.GetResultData();
var name = (string)result["name"];
};
This way I get the JsonObject without any problem and I can read all data, but when I make request to "me/feed" or "me/home" instead of "/me":
fb.GetAsync("/me/home");
fb.GetCompleted += (o, ea) =>
{
var result = (JsonObject)ea.GetResultData();
var data = (JsonArray) result["data"];
foreach (JsonObject post in data)
{
id = (string)post["id"];
}
};
then the JsonObject is empty and I get a exception when trying to access its elements. I successfully managed to POST a message to "me/feed", but why do I receive an empty response when making a GET request? I have set the access token in the FacebookClient I'm using to make the calls, is there something else that I'm missing?
Thanks!

how to get attachCamera() when load page,so when people load or refresh page they will ask for for their camera access first?

i have used this code to get camera access how i can load it on page load
private function startVideo():void
{
if (true) // TODO: Recognize no video settings
{
var camera:Camera = Camera.getCamera(cameraIndex.toString());
if (camera)
{
vidMe.attachCamera(camera);
if (outgoingStream)
{
outgoingStream.attachCamera(camera);
}
}
}
else
{
vidMe.attachCamera(null);
if (outgoingStream)
{
outgoingStream.attachCamera(null);
}
}
}
Flash shows the camera request dialog the first time you call attachCamera(). To have a user be asked upfront, before your flash application reaches any functionality, I would suggest adding it upfront in our constructor.
This dummy function puts together a fake NetConnection, and connects it to no server. Going through this upfront will present a user with the camera use dialog while your flash application is loading, thus happening on page refresh or initial load.
private function ensurePermissions() : void {
var unusedNetConnection : NetConnection = new NetConnection()
unusedNetConnection.connect( null );
var ensureCamPermissions : NetStream = new NetStream( unusedNetConnection );
ensureCamPermissions.attachCamera( myCamera );
try {
ensureCamPermissions.close();
unusedNetConnection.close();
} catch( error:Error ) {
// Ignore any errors here
} finally {
ensureCamPermissions = null;
unusedNetConnection = null;
}
}

MVC2 Json request not actually hitting the controller

I have a JSON request, but it seems that it is not hitting the controller. Here's the jQuery code:
$("#ddlAdminLogsSelectLog").change(function() {
globalLogSelection = $("#ddlAdminLogsSelectLog").val();
alert(globalLogSelection);
$.getJSON("/Administrative/AdminLogsChangeLogSelection", { NewSelection: globalLogSelection }, function(data) {
if (data.Message == "Success") {
globalCurrentPage = 1;
} else if (data.Message == "Error") {
//Do Something
}
});
});
The alert is there to show me if it actually fired the change event, which it does.
Heres the method in the controller:
public ActionResult AdminLogsChangeLogSelection(String NewSelection)
{
String sMessage = String.Empty;
StringBuilder sbDataReturn = new StringBuilder();
try
{
if (NewSelection.Equals("Application Log"))
{
int i = 0;
}
else if (NewSelection.Equals("Email Log"))
{
int l = 0;
}
}
catch (Exception e)
{
//Do Something
sMessage = "Error";
}
return Json(new { Message = sMessage, DataReturn = sbDataReturn.ToString() }, JsonRequestBehavior.AllowGet);
}
I have a bunch of Json requests in my application, and it seems to only happen in this area. This is a separate area (I have 6 "areas" in the app, 5 of which work fine with JSON requests). This controller is named "AdministrativeController", if that matters.
Does anything jump out anyone as being incorrect or why the request would not pass to the server side?
Look at the GET in Firebug or Fiddler.
Either:
There is no GET, in which case your browser cached the results from last time (cough, IE, cough); change the cache policy on the response.
There is a GET, but it doesn't match your route; fix the routing or the JavaScript, as appropriate.
As it turns out, if the Area name and Controller name are the same, it looks like MVC gets a little confused. Im not sure if this is a bug on my side, or something witH MVC, but when I remove the "/" from the name in the Json request (ie. "Administrative/Action" instead of "/Administrative/Action") it works just fine. A colleague was the one to figure this one out for me, he found some forum response on it and showed me what they did. Once I removed the "/" it worked just fine.

Actionscript Wait For Asynchronous Event Within Function

I need a little help with asynchronous events in ActionScript 3. I am writing a simple class that has two functions, both of which return strings(logic and code outlined below). Due to the asynchronous nature of the AS3 HTTPService, the return value line is always reached before a result is returned from the service, yielding an empty string. Is it possible to include some type of logic or statement in this function that will make it wait for a response before returning a value? Is there a framework that handles this type of stuff?
Call service
Parse JSON result, isolate value of interest
Return Value
public function geocodeLocation(address:String):Point
{
//call Google Maps API Geocode service directly over HTTP
var httpService:HTTPService = new HTTPService;
httpService.useProxy = false;
httpService.url = //"URL WILL GO HERE";
httpService.method = HTTPRequestMessage.GET_METHOD;
var asyncToken : AsyncToken = httpService.send();
asyncToken.addResponder( new AsyncResponder( onResult, onFault));
function onResult( e : ResultEvent, token : Object = null ) : void
{
//parse JSON and get value, logic not implemented yet
var jsonValue:String=""
}
function onFault( info : Object, token : Object = null ) : void
{
Alert.show(info.toString());
}
return jsonValue; //line reached before onResult fires
}
You should define onResult and onFault in your app – wherever you call geocodeLocation – and then pass them into your function as arguments after the address. Your onResult function will receive the data, parse the Point and do something with it. Your geocodeLocation function won't return anything.
public function geocodeLocation(address:String, onResult:Function, onFault:Function):void
{
//call Google Maps API Geocode service directly over HTTP
var httpService:HTTPService = new HTTPService;
httpService.useProxy = false;
httpService.url = //"URL WILL GO HERE";
httpService.method = HTTPRequestMessage.GET_METHOD;
var asyncToken : AsyncToken = httpService.send();
asyncToken.addResponder( new AsyncResponder( onResult, onFault));
}
And then in your app somewhere:
function onResult( e : ResultEvent, token : Object = null ) : void
{
var jsonValue:String=""
//parse JSON and get value, logic not implemented yet
var point:Point = new Point();
//do something with point
}
function onFault( info : Object, token : Object = null ) : void
{
Alert.show(info.toString());
//sad face
}
var address:String = "your address here";
geocodeLocation(address, onResult, onFault);
When the web service responds, control will pass either to your onResult function, where you will parse the Point and do something useful with it, or to your onFault function.
BTW you might run into problems calling the Google Maps geocoder this way, it's probably better to use the official SDK and take advantage of their code: http://code.google.com/apis/maps/documentation/flash/services.html