Im developing an android app and already connected everything to facebook and sucessfully shared a dialog and liked a page. Now i would like to post to feed using open graph api because i wanted to post everything in my own format, a image, title, coordinates and a small description.
Ive already created the custom open graph storie but i cant manage to make this work.
The share dialog opens and closes instantly
Namespace is roteiroobidos
Actiontype is Share
Object type is Interesting_place
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "obidosroteiro.share")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("obidosroteiro.share") //If i try to change any of these "share" the share dialog would not even open
.putObject("obidosroteiro:share", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("obidosroteiro:share")
.setAction(action)
.build();
Thanks
You have to change the way that you are calling your object/action using : instead of .
Also the setPreviewPropertyName() should contain the name of your object, in this case share.
Change to this:
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "obidosroteiro:share")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("obidosroteiro:share") //If i try to change any of these "share" the share dialog would not even open
.putObject("obidosroteiro:share", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("share")
.setAction(action)
.build();
Related
I am developing some quiz app, and want to post player's achievement on facebook.
Since I want to post the image for the achievement and Link Share of facebook doesn't support add image any more, I decided to use Open Graph.
I succeeded to post with example source for the object type of "fitness.course", but still have troubles with the object type of "game.achievement".
Share Dialog shows up, and seems OK until I click post button. But, after clicking post button, I cannot find the post on my facebook wall.
Here is my source code.
// Set image with the image on the file path
Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setUserGenerated(true)
.build();
// set object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "game.achievement")
.putString("og:title", "App Name")
.putString("og:description", "You achieved Golden madal")
.putInt("game:point", 100)
.build();
// set action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("games.achieves")
.putObject("game.achievement", object)
.putPhoto("image", photo)
.build();
// set content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("game.achievement")
.setAction(action)
.build();
mShareDialog.show(content);
For your information, the below is the example source code I succeeded with
// Set image with the image on the file path
Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setUserGenerated(true)
.build();
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "App Name")
.putString("og:description", "You achieved Golden madal")
.putInt("fitness:duration:value", 100)
.putString("fitness:duration:units", "s")
.putInt("fitness:distance:value", 12)
.putString("fitness:distance:units", "km")
.putInt("fitness:speed:value", 5)
.putString("fitness:speed:units", "m/s")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("fitness:course", object)
.putPhoto("image", photo)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
Thanks a lot in advance for your efforts.
I think I have got the reason for this. It is so disappointing. Open Graph for game.achievement seems to have been depreciated. See the link https://developers.facebook.com/docs/games/services/scores-achievements?locale=en_US
The Scores API and Achievements API are slated for deprecation. As of
April 4, 2018, they will only return empty data sets and will be
deprecated in the near future. Please see the changelog for more
information.
Also facebook depreciated Custom Open Graph. See the link https://developers.facebook.com/docs/sharing/opengraph/custom-open-graph-deprecation
I'm developing a Share Function in my Android App and i'm facing an issue with Open Graph.
I already have my Test User to publish and the SDK and Login integrated in my app.
If i use news.reads action facebook share dialog appears, i click publish but nothing is published to my Wall.
If i use news.publishes everything works ok.
Am i missing something?
Thank you very much in advance.
Maxi
This is my code:
Bitmap image = UtilityFunctions.loadBitmapFromView(mV);
SharePhoto photo= new SharePhoto.Builder().setBitmap(image)
.setUserGenerated(true).build();
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "article")
.putString("og:url", ((TextView) mV.findViewById(R.id.linkNews)).getText().toString())
.putString("og:publisher", "http://www.planetariverplate.com")
.putString("og:site_name", ((TextView) mV.findViewById(R.id.fuenteNews)).getText().toString())
.putString("og:title", ((TextView) mV.findViewById(R.id.tituloNews)).getText().toString())
.putString("og:description", "Compartido desde Planeta River Plate Android App - https://play.google.com/store/apps/details?id=com.fmbaccimobile.planetariverplate.core")
.putPhoto("og:image", photo)
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("news.reads")
.putObject("article", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("article")
.setAction(action)
.build();
ShareDialog.show(activity, content);
After a failed attempt to create my custom story in Facebook (see here)
I decided to use the "Listen" Open Graph common action pre-defined by Facebook. Here's my code:
// Facebook
mImageButtonShareOnFacebook = (ImageButton)view.findViewById(R.id.shareOnFacebook);
mImageButtonShareOnFacebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(_albumCover)
.setUserGenerated(true)
.build();
// Create an object
String fbAppId = getActivity().getString(R.string.facebook_app_id);
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("fb:app_id", fbAppId)
.putString("og:type", "music.song")
.putString("og:title", _title + " by " + _artist + " in XYZ Radio " + channel.getName() + " channel")
.putString("og:site_name", "XYZ Radio")
.putPhoto("og:image", photo)
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("music.listens")
.putObject("song", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("song")
.setAction(action)
.build();
ShareDialog.show(NowPlayingFragment.this, content);
}
});
And here's what I am getting:
The published post seems be correct, though.
So, why am I getting that "A preview will be added after you post this link to..." message? Is that the default behaviour or what am I missing? Thanks in advance...
I believe this is by design, read more about pre-caching here:
When content is shared for the first time, the Facebook crawler will
scrape and cache the metadata from the URL shared. The crawler has to
see an image at least once before it can be rendered. This means that
the first person who shares a piece of content won't see a rendered
image.
I believe a similar concept applies for OG previews.
I'm using the new Facebook API (v4.4) with ShareOpenGraphObject, ShareOpenGraphAction and ShareOpenGraphContent. I can't get the title to have an effect on the share description. I was assuming that if I added og:title then it would use the "One to One" sentence so.
Will completed {level.title} on WordBuzz.
but it's using the "One to One - Without Object Title" sentence instead
Will completed a level on WordBuzz.
The title is clearly being sent, as it's being shown in the title above the description (screenshot at the bottom), but I don't understand why it's not being used in the above sentence.
How do I get Facebook to display the level title? I'm aware there are hacks to work around this on StackOverflow, here and here. But I'm assuming it's possible to get this working as it should!
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "scribble-wordbuzz:level")
.putString("og:title", "Level 14")
.putString("og:level.title", "Level 14") // test
.putString("scribble-wordbuzz:title", "Level 14") // test
.putString("scribble-wordbuzz:level.title", "Level 14") // test
.putString("og:description", "Here's the level description")
.putPhoto("og:image", photo)
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("scribble-wordbuzz:complete")
.putObject("level", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("level")
.setAction(action)
.build();
shareDialog.show(content);
I'm trying to share open graph stories and locations for a fitness course using facebook android sdk version 4.2,
I would like to have something like this:
https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xaf1/t39.2178-6/851557_504281972964839_1538874606_n.png
but the map does not show up
basically my code look like this:
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "Sample Course")
.putString("og:description", "This is a sample course.")
.putInt("fitness:duration:value", 100)
.putString("fitness:duration:units", "s")
.putInt("fitness:distance:value", 12)
.putString("fitness:distance:units", "km")
.putInt("fitness:speed:value", 5)
.putString("fitness:speed:units", "m/s");
ArrayList<ShareOpenGraphObject> metrics = new ArrayList<ShareOpenGraphObject>();
ShareOpenGraphObject.Builder metric1 = new ShareOpenGraphObject.Builder();
String timestamp1 = dateFormat.format(new Date(realDateTime1));
metric1.putDouble("fitness:metrics:location:latitude", latitude1);
metric1.putDouble("fitness:metrics:location:longitude",longitude1);
metric1.putString("fitness:metrics:timestamp",timestamp1);
metrics.add(metric1.build());
ShareOpenGraphObject.Builder metric2 = new ShareOpenGraphObject.Builder();
String timestamp2 = dateFormat.format(new Date(realDateTime2));
metric2.putDouble("fitness:metrics:location:latitude", latitude2);
metric2.putDouble("fitness:metrics:location:longitude",longitude2);
metric2.putString("fitness:metrics:timestamp",timestamp2);
metrics.add(metric2.build());
.....
object.putObjectArrayList("fitness:metrics", metrics);
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("fitness:course", object.build())
.putString("fitness:start_time", startTime)
.putString("fitness:end_time", endTime)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
I did several tries without success, for example if I don't use the metrics array showed above and I put fitness:metrics:location:* directly on the original object builder the map is shown with a single location. Hints?
I had a similar issue, in my case I had a web backend that host the fitness course and I solved it by setting in the ShareOpenGrapAction the url of the fitness course.
In the web backend the fitness course is created using the reference stated here: https://developers.facebook.com/docs/opengraph/guides/fitness
In the app
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putString("fitness:course", url)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
Than call the show
if (shareDialog.canShow(ShareOpenGraphContent.class)) {
shareDialog.show(content);
}
Hope this helps!