I'm using Facebook Graph API with Javascript to allow the user to share a link. Simple enough.
Javascript code:
var _link = 'http://example.com/ca.a/4102/540/en/1/31';
function share() {
FB.ui({ method: 'share',
href: _link,
redirect_uri: _link,
quote: 'simple name'
},
function (response) { }
);
}
This operation results it a link generated by Facebook API:
https://www.facebook.com/v2.8/dialog/share?app_id=596131650587698&channel_url=http%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F0sTQzbapM8j.js%3Fversion%3D42%23cb%3Df2c247478a4c94c%26domain%3Dwebcand.com%26origin%3Dhttp%253A%252F%252Fwebcand.com%252Ff2f0001bcf7065%26relation%3Dopener&display=popup&e2e=%7B%7D&href=http%3A%2F%2Fwebcand.com%2Fca.a%2F4102%2F540%2Fen%2F1%2F31&locale=en_US&name=simple%20name&next=http%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F0sTQzbapM8j.js%3Fversion%3D42%23cb%3Df572851e5571f8%26domain%3Dwebcand.com%26origin%3Dhttp%253A%252F%252Fexample.com%252Ff2f0001bcf7065%26relation%3Dopener%26frame%3Df1d6415a361a248%26result%3D%2522xxRESULTTOKENxx%2522"e=Click%20here%20to%20take%20the%20interview&sdk=joey&version=v2.8
Note the &next= parameter. Facebook has wrapped the link I provided with additional data, redirecting it to Fstaticxx.facebook.com.
So now, the share feed looks like this:
The "Object reference not set to an instance of an object" error message is happening because the link I provided expects the format http://example.com/ca.a/A/B/C/D/E and if one of these / params is missing, the exception occurs. So obviously the link alteration causes this.
Passing the URL as A-B-C-D-E works fine, so my conclusion is that the / signs are being removed.
Any suggestion how to fix this?
Related
I need to show active visitors on my website based on Page title.
Example : If the user is Contact Us page, then onlycount of active visitors on 'Contact us' page is to be shown instead of entire site.
I am following Embed API Third Party Visualizations
I tried the following code but it is not working
var activeUsers = new gapi.analytics.ext.ActiveUsers({
container: 'active-users-container',
pollingInterval: 5,
query: {
filters:'ga:pageTitle==Contact'
}
});
Please help me to resolve this issue.
As I mentioned in the Github issue opened about this same question, what you're asking to do is not possible with the current ActiveUsers Embed API component (it's just for demo purposes, it's not intended to be a full-featured Real Time query component).
However, this component could easily be modified to support your use case. You'd just have to update the lines that make the API request to add your query parameters.
Here is the relevant line of code that makes the request:
gapi.client.analytics.data.realtime
.get({ids: options.ids, metrics: 'rt:activeUsers'})
.then(function(response) {
// ... do something with the response
});
To add your filter, you'd just have to change that line to something like this:
gapi.client.analytics.data.realtime
.get({
ids: options.ids,
metrics: 'rt:activeUsers',
filters: 'ga:pageTitle==Contact'
})
.then(function(response) {
// ... do something with the response
});
Of course, you'd probably rather refactor the component to accept an options object (as you show in your question), so you don't have to hard code your query, but I'll leave it up to you to make that code change.
To point you in the right direction, you should read the Embed API guide: Creating Custom Components. You'll probably also need to reference the Shared Component Reference to see the methods all components can call.
I tried this Show active visitors after filtering
it worked.
I want to create unpublished image post on facebook and then edit the message attached to it.
I can create an image by doing:
/me/photos
url: somewhere
published: false
caption: 'abc'
This, due to documentation should return
Struct {
id: numeric string,
post_id: string,
}
But it doesn't return post_id. If published is set to false the post_id is omitted. When I visit created photo on facebook I can edit attached caption and other parameters of the photo. But when I try to do it trough API I can only edit very limited amount of parameters, described here:
https://developers.facebook.com/docs/graph-api/reference/photo/#Updating
I also tried different approaches, of which most promising was to post unpublished photo, then create unpublished post with image attached. Since I'm trying to post to a page I'm using this endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.5/page/feed
/me/feed
caption: 'abc'
published: false
object_attachment: (id-from-previous-request)
If I could do it like this I could later edit the message, and the post would look the same as when using /me/photos normally.
I cannot do
/me/feed
caption: 'abc'
published: false
url: somewhere
Because this results with link post(and requires link parameter as well), which is different in look from image post.
I cannot figure what I am doing wrong - I just want to create unpublished post with attached image and then edit it. It's possible trough webpage, but all my attempts trough API have failed.
The related post_id for photo_id is always generated like this(for page):
page_id + '_' + photo_id
In case the photo was posted into different edge then instead of page_id corresponding id is used, for example it would be user id, if it was posted onto edge user/photos.
This behavior isn't documented anywhere where I could find it, nor it is guaranteed to work in the future. I contacted facebook support yet they didn't clarify if it's intended. They only said that it's by design that post_id is not returned.
I am using a Facebook social plugin share button, I want to capture the event whether the user shares the event or not.
Is there a way to check whether the user shared it or not using plugin only?
Using the FB.ui method provided by the Facebook JavaScript SDK, you can pass a callback as the second argument and check for the post_id on the response object.
FB.ui({
method: 'feed',
link: 'http://www.example.org/',
picture: 'http://placehold.it/400x400',
caption: 'Title',
description: 'Some description...'
}, function (response) {
if (response.post_id) {
// This post was shared
} else {
// This post was not shared
}
});
More information can be found in the Facebook share documentation.
Using Facebook's JavaScript SDK I am trying to open a share dialog from within a canvas app, which I am able to do fine. However, when I try to amend the message that gets sent along with it, I'm unable to get things working.
I'm aware I can change the message using meta tags within the document itself, as Facebook scrapes the page on the link to grab og:* tags from the head of the doc, but the message I want to share is specific to this user's experience, for example: "I just scores 9/10 on this quiz, can you do any better?".
I have set up an action, object and story, which are being linked in fine. Below is my code, which isn't changing the message:
FB.ui({
method: 'share_open_graph',
action_type: 'the-dog-breed-quiz:take',
action_properties: JSON.stringify({
quiz:'https://apps.facebook.com/removed',
message: 'I scored 15 out of a possible 20 on the Test quiz. Can you do any better?'
})
}, function(response){});
After much searching and piecing things together I have the following solution.
The process is thus:
Have a button to be clicked. This is a must, as you'll need to provide proof of user interaction in order to show a dialog.
Ensure you have publish_actions permission at point of login
Create a user action. I did this using JS SDK, see below code.
Take the ID from the user action and reference that as part of the UI call
.
FB.api(
'me/objects/your-app-namespace:quiz',
'post',
{'object': {
'og:title': 'Blah blah',
'og:type': 'your-app-namespace:quiz',
'og:image': 'https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png',
'og:description': 'keyboard mashdfhg nfkg kfd hg',
'fb:app_id': 'removed'
}},
function(response) {
// handle the response
FB.ui({
method: 'share_open_graph',
action_type: 'your-app-namespace:take',
action_properties: JSON.stringify({
quiz:response.id,
})
}, function(response){
console.log(response);
});
}
);
I'm trying to delete an object created by a story, but I'm getting the following error :
(#100) Cannot delete object not created via the API
I used the FB.api in javascript to create a story with news.reads (works), I can delete the story with the ID too. But the object created for the story still exists, I can see it in the Graph API, but cannot delete it.
I want to fix this issue because if I try to create a story with the same article link, if I change the content (the same link refers to a new article), facebook will keep the old settings (title, image and description don't change).
You can force facebook to re-scrape your site when you use scrape=true in your next call:
FB.api(
'/',
'post',
{id: <your article url>, scrape: 'true'},
<your callback function>
);