How to share Facebook App Links to Facebook with preview? - android

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?

Related

Sharing a link on facebook with a full sized image instead of a thumbnail

I am working with a project where the user will be able to share a product from my app to facebook. In this action, the user will edit the following data:
The quote/description of the product.
Set a place for the post.
Share an image from my app gallery.
When the user shares my product it generates a standard hashtag, and the user may select a place for check in.
Here is the image of the desired action.
Sharing product on Facebook
So i followed several tutorials on youtube and the documentation from facebook so i managed to use SharePhoto and Share Link with success. In my share button im using share link and setting the following properties :
String url_link_loja = "www.centauro.com.br";
ShareHashtag.Builder hashtag = new ShareHashtag.Builder();
hashtag.setHashtag("#Olympikus");
String url_imagem = "https://static.olympikus.com.br/produtos/tenis-olympikus-thin-2-feminino/91/D22-0304-791/D22-0304-791_zoom1.jpg?resize=1200:*";
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(url_imagem_test))
.setQuote(url_link_loja)
.setImageUrl(Uri.parse(url_imagem))
.setShareHashtag(hashtag.build())
.setPlaceId("Avenida Paulista")
.build();
shareDialog.show(linkContent);
Then, when i share with my app i get just a thumbnail of the image instead of a full sized image.
Share Dialog on Nexus xl
When i use Share Photo instead, i get the full image on the dialog window just the way i want, however it seems its not possible to add hashtag and quote on this object. I tried to fix this using open graph, so i used the book example from the documentation and tried do add image, but when i do, i get a callback error message that dos not specifies the problem( i already checked, its not the commom namespace error).
So, i need some advice on the matter, any insight will be helpful.

Share Score on Facebook android

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

How to implement Facebook App Link in Android with example

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.

Share an image and a link to my android app using Facebook sdk

In my camera app for Android i would like to share a photo taken by the user to the user's facebook wall. I would like it has:
a text description written by the user (like in a shareDialog)
the image taken with my camera app
the link to the image itself in the album (to swipe to the previously uploaded ones)
some text (caption+description) about my app
a link to my app (with icon?) in google play
Here's a picture of what i want: (tweet-to-facebook posts are very similar to this, so i think it can be done!)
How to achieve this?
Should i use Open Graph?
I tried following developers.facebook tutorials, but i failed!! i think samples are buggy! It's very frustrating...
Please help, i need someone to show me the right way!
EDIT
actually this is my code, no foto is shown:
private void shareWithFacebookOpenGraph(String pathToImage) {
Log.i("SHARE", "1. share with OpenGraph");
OpenGraphObject photo = OpenGraphObject.Factory.createForPost("myapp:photo");
photo.setProperty("title", "MyApp Photo");
photo.setProperty("image", "http://play.google.com/to_my_app_launcher_icon");
photo.setProperty("url", "http://play.google.com/to_my_app");
photo.setProperty("description", "Image taken with myApp for Android");
List<File> files = new ArrayList<File>();
files.add(new File(pathToImage));
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("photo", photo);
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "myapp:take", "photo")
//.setImageAttachmentFilesForObject("image", files, true) // Error: image is not a property
//.setImageAttachmentFilesForAction(files, true) // Error sharing pictue: null
//.setImageAttachmentFilesForObject("photo", files, true) // can't create Collection (?!?!)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}

Android Facebook Share Dialog's content not shown in home page

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);
}

Categories

Resources