Is it possible to post on Facebook from my Android application and this post function as App Link? Where if someone using Facebook application tapped on this post it will be directed to G.P. to install my app, and if it's installed it will open my app with enough data to view this post in my app activity?
So far I couldn't find an example that shows how to create an App Link object, and how to include data in this object to be retrieved later from intent -> extras, and I'm totally confused how to implement it in Android.
For example, from my application I want to share an http://youtube.com/xxxxx link in a post on Facebook, how to create the App Link using Facebook App Link host feature?
Edit 1:
I need to understand something about app linking, do I create an app link for each post will be posted from my application, or app link is created once to represent my application?
Edit 2:
How to get my app name to be in Blue as Instagram and clicking on it opens my application or go to my Google Play to install if not installed
Edit 3:
This is the code I use to share, but I don't get my application name a "clickable blue link" as Instagram as in the picture:
ShareDialog shareDialog = new ShareDialog(mMainActivity);
if (ShareDialog.canShow(ShareLinkContent.class))
{
ShareLinkContent linkContent;
if(aURL == null)
{
linkContent = new ShareLinkContent.Builder().build();
}
else
{
linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(aURL))
.build();
}
shareDialog.show(linkContent);
}
Shall I make a specific changes in my application settings page on Facebook dashboard?
You should use open graph actions for that. first you should create a object . then add an action type. then needs to create a story. & you have to submit for review process your facebook app. Normally share code looks like this. read the docs https://developers.facebook.com/docs/sharing/opengraph/android. & you need to use app links - https://developers.facebook.com/docs/applinks/android
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "books.book")
.putString("og:title", "A Game of Thrones")
.putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
.putString("books:isbn", "0-553-57340-3")
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
ShareDialog.show(activityOrFragment, content);
If I understand your question correctly, you want to post to facebook(a URL) from your app.
What you can do is:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, your_link_here );
startActivity(Intent.createChooser(intent, "Share via"));
This will open up a list of apps where you can share your link which includes facebook app if it is installed. Also have a look at facebook's TOS. You cannot prefill a message as it is against their policy. If you want to share some text along with your URL you will have to use facebook's SDK.
I tried the same thing. It turns out that your app should be present on app center (facebook). Then only it will turn into blue link.
In my case, I tried clicking the link, but it landed on a page which said:
Misconfigured App Sorry, "My app" hasn't been approved for display in
App Centre.
So I got the hint from this.
Related
I am integrating facebook SDK in my app, but I am a little confused by the sharing system.
My app is educationnal, and I'd like my user to be able to brag as "I had 100/100 on the test n°xx" and share it on facebook, just like you could do with Runtastic.
For those who wouldn't know it, here is what Runtastic shares look like (the example is in French but you get the idea) :
Since my app is not a game, this is not possible with Open Graph Stories (there is no type for educationnal), and Custom Open Graph Stories are now deprecated, so no object is relevant and I cannot create my own anymore.
Knowing that, how can I make a ShareDialog that will look like this, with a big logo and a non-modifiable text beside, linking to a website ?
The Sharing documentation tells everything about sharing a single thing but it is not really helpful when you want to combine it with text.
The closest thing to what I want would be to use ShareLinkContent with a link to my app on the playstore and a quote like. It do the trick, but it looks more like the user is just sharing a link (which is true), more than he is bragging about an achievement.
I could also share the logo as a photo and put the brag as a caption, but then the logo would ba too big and the caption has to be modifiable so everyone could tell he got 100/100.
NB : the text in french means "[this person] just terminated a run of 27.94 km in 3 hours and 6 minutes, saved with Runtastic app". I'd like my app to show "[this person] just got 100/120 on 2016 session, saved with MyAppName app".
NB2 : I haven't got any server, just a playstore link, a facebook app and a facebook page
There you go...
This is my function which will make an object with a title & description, also with a picture from a remote URL (but you will need to create a bitmap of that picture, for that I am using Glide
private static void shareFacebook(Context context, Bitmap picture, String title, String videoURL, String description) {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(picture)
.setCaption(context.getResources().getString(R.string.floh_site))
.setUserGenerated(true)
.build();
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "books.book")
.putString("og:url", videoURL)
.putString("og:title", title)
.putString("og:description", description)
.putPhoto("og:image", photo)
.putString("books:isbn", title)
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.wants_to_read")
.putObject("book", object)
.build();
ShareOpenGraphContent c = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
ShareDialog.show(FlohApp.getTopActivity(), c);
}
I wanna to implement a share to Facebook function to my app.My app is Android only app.The data that I want to share it to Facebook is text and image that generated by user.So basically when other user click on a "Share" button,will open the ShareDialog and post it to their Facebook account.
In order to do this,I successfully get the App Links by using the Mobile Hosting Api,I share it to facebook,then click it,it can direct to my app or Play Store.
But now the problem is,the appearance in Facebook of the app link I share is like below
I try to use .setImageUrl , .setContentDescription but this is deprecated.
Then I read on this question and try to implement my code like below
Bitmap image = null;
SharePhoto photo = null;
try {
URL url = new URL(postImageUrl);
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (image !=null) {
photo = new SharePhoto.Builder()
.setBitmap(image)
.setImageUrl(Uri.parse(postImageUrl))
.setUserGenerated(true)
.build();
}
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "article")
.putString("og:title", "A Fun Story in Messenglass")
.putString("og:description", postStatus)
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("news.reads")
.putObject("article", object)
.putPhoto("image",photo)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("article")
.setAction(action)
.setContentUrl(Uri.parse(Facebook app link)) //here is the app links
.build();
shareDialog.show(getActivity(),content);
By this Open Graph story,my link share to Facebook have preview,but when I click the link,then not redirect me to my app,but redirect me to App center of Facebook.
I try to submit my app for review for Open Graph story,but my developer App Dashboard dont have any Open Graph stories section.
Here is the outlook of the link in Facebook,this is good,but not lead me to my app when clicked,but lead me to App center
This is Docs I read about the Open Graph Review
https://developers.facebook.com/docs/apps/review/opengraph/
So what I missing,so I can share my app links that from Mobile Hosting Api to Facebook,with a beautiful preview?Please give me some suggestion
UPDATE
After I implement the code above and test in real device,I successfully add the user generated photo and the text to the share dialog.But when I click "Post" in the share dialog,it pop out a progress dialog "Sending" then dismiss,no any other error or something,but I check back Facebook timeline,I dont have the post that shared appear.
Here is the outlook at the share dialog in my app,but didnt appear in Facebook timeline
Can somebody tell me what I missing?What I suppose to do in order to share the applink generate by Mobile Hosting Api,and appear in Facebook timeline with preview photo or description in the post?
I want to share my game score on facebook. I checked lots of links and every post people are saying that POSTING on facebook using INTENT is not possible.If we are using intent than we can share only link.
If we have to share something on facebook than we have to use FaceBook SDK.
I have another doubt that all questions and answers were posted before Year 2014. Is any new thing come after year 2014.
My actual question is that, Is it possible to share score on Facebook using Intent or i have to use Facebook SDK ?
below is the intent code which i used for my application which is not working ......
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Share on"));
and below is the FacebookSDK code ...and Problem in this it is not showing score on the Post only link image is showing, and title & description is missing.
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
linkContent = new ShareLinkContent.Builder()
.setContentTitle(title)
.setContentDescription(description)
.setContentUrl(Uri.parse(link)).
.setImageUrl(Uri.parse(imageLink)
.build();
shareDialog.show(linkContent);
}
I used ShareDialog because
The Share dialog switches to the native Facebook for Android app, then returns control to your app after a post is published. If the Facebook app is not installed it will automatically fallback to the web-based dialog.
Below is the output ..........
#pravin this is error coming after your share API use
#Pravin this is my code of your share answer........
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_facebook);
Button mShare= (Button) findViewById(R.id.share);
mShare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "game.achievement")
.putString("og:title", "Name of your game")
.putString("og:description", "description. You can share your score here")
.putString("game:points", "445")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("games.achieves")
.putObject("game", object)
.build();
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("game")
.setAction(action)
.build();
ShareDialog.show(Facebook.this, content);
}
}
});
shareDialog = new ShareDialog(this);
}
Thanx in advance ................
After long searching i found this as work for me in my Project till the actual answer will come ..........
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
linkContent = new ShareLinkContent.Builder()
.setQuote("Hi Guys I have completed Game 30 in 19 seconds in this game")
.setImageUrl(Uri.parse("https://lh3.googleusercontent.com/jUej7mN6M6iulmuwmW6Mk28PrzXgl-Ebn-MpTmkmwtOfj5f0hvnuw8j0NEzK0GuKoDE=w300-rw"))
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mobtraffiq.numbertap&hl=en"))
.build();
shareDialog.show(linkContent);
}
NOTE:-In this code its shared a quota. If any one get other answer please post with output.
Output:-
Please post guys if you get the actual answer of this question ....
Thank you for all the user who make their effort .......
I have learn many thing due to your answers .......
enjoy coding .........
Scores API
If you just want to share score you can use Scores API(Read Create or Update a Player's Score section). There is very less and unclear information in provided link so below code snippet might work for you.
Bundle param = new Bundle();
param.putInt("score", 100);
new GraphRequest(
your_access_token,
"/USER_ID/scores",
param,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
Achievements API
Use Achievements API if you want to publish achievements in your game and reward players with scores for completing those achievements.You have to use Open Graph Stories to publish your game achievements on Facebook. Before publishing stories on behalf of people, You will have to submit them for review. Read this link for more information.There are two ways to publish an Open Graph story:
Using the Share dialog
Using your own custom interface
As you are using share dialog, I am going to throw some light on how to post game score using share dialog.
Create an object with the object type game.achievement and set the properties on that object.
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "game.achievement")
.putString("title", "Title of the achievement type.")
.putString("og:description", "description. You can share your score here")
.putInt("game:points", Points in integer)
.putString("og:url", "url of achievement type")
.putString("og:image", "image url")
.putString("fb:app_id", "The App ID that owns this achievement type")
.build();
In above code snippet key is Object Properties and game.achievement is Object Type. Here is documentation for game:points.
Then create an action and link the object to the action.
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("games.achieves")
.putObject("game", object)
.build();
You can find different ActionTypes here.
Finally, create the content model to represent the Open Graph story.
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("game")
.setAction(action)
.build();
All objects and action types in your code must be lowercase. All
property names require namespaces.
Present the Share dialog by using the show method on ShareDialog.
ShareDialog.show(activityOrFragment, content);
Summary:-
The Scores API and Achievements API make it easy to build social
leaderboards, persist player scores and award achievements to players
in a social and cross-platform format. With the Scores API, you can
store and reset a player's high-score and pull back a list of their
friends' scores to populate a leaderboard. With the Achievements API,
you can define a list of custom achievements that players can complete
in your game, along with a score value that can be earned with each
achievement.
Note:-
Both the Scores API and Achievements API are only available for apps
that are categorized as Games.
Because these API let developers write information about player game
state to the Graph API, they both require publish_actions permissions,
which is subject to Login Review. To retrieve Score and Achievement
information about a player's friends, both the player and their
friends need to grant the user_friends permission.
Hope this will provide you and other users enough information on game integration with Facebook.
Just try the below snippet,
call wherever you want like below
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(mContext);
shareDialog = new ShareDialog(mContext);
shareScoreonFB("345"); // just pass your score here in string format. call this inside click listener.
// GLOBAL FUNCTION TO SHARE SCORE ON FB
void shareScoreonFB(String score)
{
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Your score is : "+score)
.setContentDescription("Any description that you needed")
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mobtraffiq.numbertap&hl=en")).build();
shareDialog.show(linkContent);
}
NOTE: Make sure you initialize the Facebook SDK.
Hope this helps you, let me know for queries.
I believe that the Facebook SDK uses a background Activity for the actual data transfer, but you still need to make your own activity, its layout, and the examples on here show you how to create your own Sharing and Login tools
You have to use Facebook SDK to do this, I think the main reason is about security.
This is a simple snippet for photo sharing example (not related to your question but i think you know you can't not do it by using Intent):
private void shareImage() {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bmp)
.setCaption("Simple puzzle")
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, null);
}
Well, there are 3 things you should do :
1) Categorize your app as Games on Facebook Developers
2) Use the Achievements API and Scores API
3) Facebook for Developers officially has an answer to your question. Please refer to the link https://developers.facebook.com/docs/games/services/scores-achievements
[ OPTIONAL ]
If you want to study about General Sharing from your app by users than this link Facebook SharingAddit might also help you in as General Sharing of content from your app
I am working on an app that I want to be able to post to Facebook wall. The language used for the app is non-latin based character set. Hence, the user types the content to share using the app itself and then share it on facebook without going to the ShareDialog as the content is already typed. I am using Facebook SDK for Android 4.+. Can anyone help me on doing this? All example I got is posting using ShareDialog. Facebook SDK seems to have classes like ShareLinkContent, SharePhoto, ShareMedia but no class to attach simple text content which I am trying to do. Or, can I make the content already typed appear on the ShareDialog's EditText?
Facebook does not allow you to pre-fill the ShareDialog's text. As far as I know there also is no other way to post content on a user's wall.
What is possible is share a link using the ShareDialog, and you can pre-fill the link description and other attributes like image and title but I guess that's not what you want.
An example of that is:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentDescription(descriptionString)
.setContentUrl(Uri.parse(urlString))
.setImageUrl(Uri.parse(pictureUrlString))
.setContentTitle(titleString)
.build();
ShareDialog dialog = new ShareDialog(this);
dialog.show(content);
private void showFacebookShareDialog() {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Title")
.setContentDescription(
"Share Text")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
}
I using "ShareDialog" for sharing a link from my app to Facebook wall. When i post a link, it shows the content only in user's timeline and not in home page. What i'm doing wrong?
I'm doing something like that:
// This is how i invokes the shareDialog
FacebookDialog shareDialog = createShareDialogBuilderForLink().build();
private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setPicture("picture url")
.setName("name")
.setLink("link url");
}
User's timeline:
Home page:
In home page only shows the name of the app which take it from the link i setted(app in google play) without showing the content of the link(descriptiion, name, Caption...).
Its because the user chose to not share the link publicly, do you see the little lock icon alongside the time the link was shared? It shows that link is not shared publicly, if its public the icon changes to globe icon.
What to do now?
1) I don't know whether Facebook API allows to set permissions on the post but you can try, see API documentation.
2) Many users by default set the share permission to private, see whether your account has it private by default by going in Facebook settings.
How about this
ShareDialog shareDialog = new ShareDialog(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Title")
.setContentDescription("Description")
.setContentUrl(Uri.parse("Url"))
.build();
shareDialog.show(linkContent);
}