Open Facebook page via Facebook app - android

How can I open Facebook page using insalled Facebook app? Exactly page, not profile, because fb://profile works fine.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/page_id")));
Seems like fb://page isn't working, because it's just opens feed.

fb://page/{id} is the way to go:
final String url = "fb://page/" + facebookID
Intent facebookAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
facebookAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(facebookAppIntent);
Are you sure you are using the ID number of your Facebook page and NOT the username?
What I mean is that if, for example, you want to open the Facebook page of Facebook itself (i.e. https://www.facebook.com/facebook) you have to use:
fb://page/20531316728
Since 20531316728 is the ID of the Facebook page (while facebook is the username).
If you don't know the ID of your Facebook page, you can retrieve it opening:
https://graph.facebook.com/{username}

Make Sure That You are Using the page id of your page correctly
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("fb://page/YOUR PAGE ID"));
startActivity(intent);

i think u should use
https://www.facebook.com/
instead of fb://page/ or fb://profile or something.
I hope it's helpful!

Related

How to open facebook app user-timeline page for a specific id from my android app?

I am trying to open facebook app for a specific user profile.
This is my code for opening the facebook intent:
try{
Toast.makeText(getActivity().getApplicationContext(),
facebook_id,
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + facebook_id));
startActivity(intent);
}catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/UserNamePage")));
}
This is how I received the user_id:
user.getId();
(The user is a GraphUser object from facebook sdk) Is this the correct way to get the user id and use it for openning the inetnt? Because this is not worked for me.
If you are using Graph API 2.x, then the user ID you have is an app-scoped user id, and there's no support for getting to a user profile from an app-scoped id in the Facebook app.

Open page in Facebook,Twitter and Google Plus app from other app - Android

I'm working on an application where I need to integrate the social functionality of the different social networks: Facebook, Twitter, Google+.
For now, in Facebook and Twitter i'm recognized if the user has a native application and if he does, I'm opening it and show him my fan page.
For Twitter I use the next code:
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
And for Facebook the next code:
try{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + PROFILE_FACEBOOK_APP_ID));
startActivity(intent);
}catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/UserNamePage")));
}
Now I want to do the same thing for Google+. I saw that I can browse to my fan page with the next Url https://plus.google.com/MY_PAGE_ID/, but it keep asking me if I want to open it with Google+ application or with the browser, and I want that he will open it with the application automatically, without asking the user.
Is there a simple way to do this?
Thanks.
Found a solution:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.plus",
"com.google.android.apps.plus.phone.UrlGatewayActivity");
intent.putExtra("customAppUri", "FAN_PAGE_ID");
startActivity(intent);
I think this is quite safe, because we do not need to specify the component, just the google+ app package name:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://plus.google.com/[Google+ID]/"));
intent.setPackage("com.google.android.apps.plus"); // don't open the browser, make sure it opens in Google+ app
startActivity(intent);
Unknown if google plus needs some other information in the Intent but as general Android solution you can explicitly set the target. You will need the package name of google+.
More info here: http://developer.android.com/reference/android/content/Intent.html#setPackage%28java.lang.String%29
For example:
Intent.setPackage("com.google.android.apps.plus"); //Don't know the exact package name

Android : Intent twitter uri

In my android application I want to redirect the users to my twitter profile page and I use this code :
Inrent i : new Intent(Intent.ACTION_VIEW,Uri.parse(''https://www.twitter.com/MYUSER));
startActivity(i);
If I choose the browser it work fine but if I choose twitter application it show a Toast "Impossible to.complete the action". How can I resolve this problem ? Thanks
I believe you are missing the setData() method:
String url = "http://twitter.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Please read more here: How can I open a URL in Android's web browser from my application?
Let me know if this helps!

Opening Facebook app with another ? With the "Twitter way"

My app needs to display a Facebook account. So I would like the Facebook application opens or if it is not available, the web browser. Currently I can open the Twitter app with this way and the system ask what to do (Twitter app or the browser).
Here is the code:
WebView myWebView = (WebView) findViewById(R.id.webViewProfile); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("https://mobile.twitter.com/"+name); // Specify the URL to load when the application starts
myWebView.setInitialScale(1); // Set the initial zoom scale
myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control
myWebView.getSettings().setUserAgentString("BumpMe");
This method is very good and I want to have the same result for Facebook. Currently I can open the Facebook app like that:
String uri = "facebook://facebook.com/info?user="+fbid;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
But if the application is not installed it won't work...
How can I do it like for twitter ?
Thanks
The reason this works with Twitter is that the Twitter app handles https://mobile.twitter.com/* URL's in its intent filters; so when you issue an intent that has that URL, the Twitter app gets called. So the only way to do this with Facebook (or any other app) would be to use a URL that matches one of the patterns declared in its intent filters. Maybe http://m.facebook.com/... ?
Instead of offering the user the choice of app or browser, another way is to try to open the app, and if that fails to open the web page. Here is how I do that for Twitter:
long userID = tweet.getUser().getId();
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=" + userID));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/intent/user?user_id=" + userID)));
}

How can I link to the page of a specific Facebook newsfeed post (in the application or browser)?

In my Android app, I log in using the Facebook SDK and display posts from the users' newsfeed. I want to give them the option to comment or like a post, but I don't want to implement that. So, my solution is to allow the user to click on the post, which will then load the post page in either the official Facebook App, or just the mobile facebook website. Either way is fine for me.
I googled around and was not able to find a suitable way to deliver an intent to launch the Facebook app to a specific post page. So, I decided to try to launch the browser and navigate to the mobile Facebook website to the specific post. I build the url string using information about the current user, the id of the post, and the id of the friend it belongs to. This url is exactly the same url I see when I browse to the page in my browser from my newsfeed. Like so:
String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
However, when the browser loads, I get a page that says "Sorry, something went wrong. We're working on getting this fixed as soon as we can." I have tried both touch.facebook.com and m.facebook.com.
I am looking for any solution that will either allow me to open the mobile site to the chosen post, or to launch the Facebook app to the chosen post activity.
I just figured this out. It turns out that the post id that I got from the json result of a newsfeed request to the graph api has extra information. The post id that I got from the newsfeed result is in the form "friendid_postid." In the link, however, the "story_fbid" tag should be set to just the postid portion. Then it works!
This is the code I used:
String postId = idTextView.getText().toString();
postId = postId.substring(postId.indexOf("_") + 1, postId.length());
String friendId = friendIdTextView.getText().toString();
String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

Categories

Resources