Game Development Community

HttpObject and Facebook API

by Ben Hamlett · in Torque Game Builder · 07/13/2012 (5:29 am) · 3 replies

would it be possible to have a user login to facebook through my game and fetch there Avatar? I would like to do this to set there avatar as the characters FACE!!! ;)

#1
07/13/2012 (8:31 am)
Yes that is possible. Not sure how but I'm 100% certain it is possible.
#2
07/13/2012 (10:51 am)
me either, I think the best way to do it would be something on the lines of

function avatar()
{
%obj = new HTTPObject();
%address = "http://graph.facebook.com";
%path = "/vienem/picture";
$avatar = %obj.get(%address, %path, "");

$hero.setImageMap($avatar);
}

then calling the function avatar() later on but I am unsure if Torque 2D can set an image map from a URL, would make life easier if it could haha.
The code above has been tested but returns;

Call to get in avatar uses result of void function call.
t2dStaticSprite::setImageMap() - t2dImageMapDatablock Datablock is invalid! ()
#3
07/19/2012 (9:19 am)
When you use the HTTPObject, it's usually best to give it a class name.

function avatar()
{
  %obj = new HTTPObject() { class = "AvatarRetriever"; };
  %address = ...;
  %path = ...;
  %obj.get( %address, %path );
}

function AvatarRetriever::onDNSResolved( %this )
{
}

function AvatarRetriever::onDNSFailed( %this )
{
}

function AvatarRetriever::onConnected( %this )
{
}

function AvatarRetriever::onConnectFailed( %this )
{
}

function AvatarRetriever::onLine( %this, %data )
{
  // This is where you'd use the %data
}

Unfortunately, I think it would be really hard to get the image from the %data.

There's a resource for displaying images from the web. I looked at the TGEA version of the code and it could be adapted for T2D, but only if you're comfortable with C++.