Open Facebook Profile in Android SDK -



Open Facebook Profile in Android SDK -

note: issue arises when facebook app installed.

i'm trying open user's facebook profile page when imagebutton clicked. after looking @ this suggested method more recent facebook app versions, it's working, exception of users friends logged in user (in app), or logged in user themselves.

the process is:

image button clicked call facebook graph api made link user's profile via facebook id (stored in our database) a new intent created checking see if facebook app installed, , generating right uri a new activity started generated intent

because we're using facebook graph api v2.0, username field removed graphuser object in json. problem facebook link (graphuser.getlink()) either:

an app-scoped (protected) link if user (logged app) not friends user profile trying view; format : https://www.facebook.com/app_scoped_user_id/{protected-id} a 'normal' facebook link user's real id (unprotected); format is: http://www.facebook.com/{real-user-id}

the real problem facebook uri when app installed expects either:

an app-scoped link a link username attached it, not {user-id}

however, web version (opened in web view) doesn't care. link can app-scoped, username-based or id-based. works webviews.

since username inaccessible in graph api v2.0, i'm getting null values, means facebook app can't generate right uri expects (username-based), id-based or app-scoped.

here code i'm using create intent:

public static intent getfacebookintent(string facebookprofileurl) { packagemanager pm = app.getcontext().getpackagemanager(); uri uri; seek { pm.getpackageinfo("com.facebook.katana", 0); uri = uri.parse("fb://facewebmodal/f?href=" + facebookprofileurl); } grab (packagemanager.namenotfoundexception e) { uri = uri.parse(facebookprofileurl); } homecoming new intent(intent.action_view, uri); }

and here onclick() method on imagebutton:

new request( session.getactivesession(), string.valueof(mate.getfacebookid()), null, httpmethod.get, new request.callback() { public void oncompleted(response response) { graphuser g = response.getgraphobjectas(graphuser.class); string fburl = g.getlink(); // todo: if link not contain 'scoped', need username, not id string otherurl = "https://www.facebook.com/" + myappuser.getid(); string finalurl = (fburl.contains("scoped")) ? fburl : otherurl; intent intent = getfacebookintent(finalurl); intent.setflags(intent.flag_activity_new_task); context.startactivity(intent); } } ).executeasync();

i need username if app installed, otherwise web view deals should.

so question: how can facebook username id facebook app? or, is there different uri facebook app expects can business relationship for, using ids , not usernames?

you should able utilize fb://profile/{user-id} url format launch native apps. allow utilize user id instead of username. rewrite getfacebookintent method as:

public intent getfacebookintent(graphuser user) { packagemanager pm = this.getpackagemanager(); uri uri; seek { pm.getpackageinfo("com.facebook.katana", 0); uri = uri.parse("fb://profile/" + user.getid()); } grab (packagemanager.namenotfoundexception e) { uri = uri.parse(user.getlink()); } homecoming new intent(intent.action_view, uri); }

you phone call method , pass in graphuser object.

android facebook facebook-graph-api

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -