My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Examples  
Updated May 16, 2011 by erja...@gmail.com

API Calls / Examples

Reading

// Objects
JsonObject user             = FbGraph.getObject("btaylor");
JsonObject page             = FbGraph.getObject("cocacola");

// Connections
JsonArray friends           = FbGraph.getConnection("me/friends");
JsonArray newsFeed          = FbGraph.getConnection("me/home");

// Selection
JsonObject fields           = FbGraph.getObject("bgolub", Parameter.with("fields", "id,name,picture").parameters());
JsonElement ids             = FbGraph.api("", Parameter.with("ids", "arjun,vernal").parameters());

// Picture
String profilePicUrl        = FbGraph.getPicture("me");

// Paging
JsonArray filteredLikes     = FbGraph.getConnection("me/likes", Parameter.with("limit", "3").parameters());
JsonArray filteredSearch    = FbGraph.getConnection("search", Parameter.with("until", "yesterday").and("q", "orange").parameters());

Searching

// Public search
JsonArray publicPostSearch  = FbGraph.getConnection("search", Parameter.with("q", "watermelon").and("type", "post").parameters());
JsonArray publicUserSearch  = FbGraph.getConnection("search", Parameter.with("q", "mark").and("type", "user").parameters());

Publishing

JsonElement post            = FbGraph.publish("me/feed", Parameter.with("message", "Hello World!").parameters());

Deleting

Boolean deleted             = FbGraph.delete("OBJECT_ID");

Analytics

JsonArray data              = FbGraph.getConnection("APP_ID/insights");
Comment by ehi.bini...@gmail.com, May 6, 2011

Can you share an example for a complete controller ?

Would you inherit the module or import it into the controller ?

Comment by project member erja...@gmail.com, May 16, 2011
// [...]
import play.modules.facebook.FbGraph;
import play.modules.facebook.FbGraphException;
import play.modules.facebook.Parameter;
// [...]
public class Application extends Controller {
// [...]
    public static void facebookLogin() {
        try {
            JsonObject profile = FbGraph.getObject("me"); // fetch the logged in user
            String email = profile.get("email").getAsString(); // retrieve the email
            // do useful things
            Session.current().put("username", email); // put the email into the session (for the Secure module)
        } catch (FbGraphException fbge) {
            flash.error(fbge.getMessage());
            if (fbge.getType() != null && fbge.getType().equals("OAuthException")) {
                Session.current().remove("username");
            }
        }
        redirect("/");
    }
}
// [...]
Comment by bhatta...@gmail.com, May 22, 2012

the module facebook is not avialable in my app, am I doing somethig wrong?

Comment by sajit.ku...@gmail.com, Jun 1, 2012

Is this compatible with Play 2.0?

Comment by project member erja...@gmail.com, Jun 12, 2012

No, the module is compatible with Play 1.2.x.

Play 1.2 and Play 2.0 are two different beasts.

Comment by ere...@gmail.com, Sep 10, 2012

I want to upload a photo, I'm doing that:

JsonElement? post = FbGraph.publish("me/photos", Parameter.with("image", "/home/getho/Escritorio/imagenLarga.jpeg").with("message", "Mi primera foto").parameters());

But I get this error:

HttpResponse?: 400: {"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}

I think that I have to configure the call with this: 'fileUpload' => true but I don't know where can i config this in FbGraph module.

Thanks.

Comment by phil...@gmail.com, Feb 10, 2013

Is version 0.6 compatible with Play 1.2.5? Or do I have to use the version (0.4) found on the play modules site?

Comment by project member erja...@gmail.com, Feb 28, 2013

Yes, version 0.6 is compatible with play 1.2.5.

Comment by project member erja...@gmail.com, Feb 28, 2013

@eresre

If you need access more information (or publish data), such as the user's birthday or wall, you must request permissions. You can do this by adding the permissions you need to the scope attribute of the <fb:login-button> (e.g. scope="email,user_birthday,read_stream,publish_stream").

https://developers.facebook.com/docs/reference/login/#permissions


Sign in to add a comment
Powered by Google Project Hosting