I'm using the Facebook send dialog to send links to Facebook posts. But I get the following error back from the Facebook API:
API Error Code: 100
API Error Description: Invalid parameter
Error Message: 'link' is invalid.
This is the JavaScript:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// assume we are already logged in
FB.init({appId: '569858063028330'});
FB.ui({
method: 'send',
link: 'https://www.facebook.com/benjerryuk/posts/10151500944440101'
});
</script>
You can run it here:
http://jsbin.com/welcome/62834/edit
Facebook send dialog documentation: https://developers.facebook.com/docs/reference/dialogs/send/
I couldn't find it written specifically, but from my attempts it seems that facebook does not accept links to itself for some reason - I can't confirm this, but I got the same result even when I put links of public posts or profiles.
You might have the link refer to your app, which will redirect to the correct facebook post.
Another note: while showing this dialog, facebook loads the given link with AJAX, which means that A) it must be an active URL and B) you cannot use localhost.
Hope that helps.
Related
I have a website with some dynamic urls (for example a page who show event details thanks to event id in get variable), but during the share with facebook, at the first attempt the thumbnail image doesn't appear due the page isn't already fetched by facebook.
Then I must go to the debugger https://developers.facebook.com/tools/debug/og/object/ and submit every pages to get a valid thumbnail to the users.
There's a script or a way to send multiple links to this debugger, or there's another way to achieve the indexing of new pages by facebook?
You can refresh the Open Graph tags with a POST request to the Graph API, i think it´s not in the Facebook docs (at least i could not find it) - but it definitely works:
$.post('https://graph.facebook.com', {
id: 'http://www.yourdomain.com/somefile.html',
scrape: true
}, function(response) {
console.log(response);
});
Just an example with jQuery, of course you can just use CURL on the server too.
I can post a photo IF I had the time to get an app approved. I can share a link that pulls in a photo from THAT page. The goal is to post a link that goes to X, but the image is hosted somewhere else.
Is this possible?
Yes, it's possible by using the JavaScript SDK and the Share Dialog. For example, I can do the following, which shares a link but with a custom image, name and caption. It basically overwrites all the OG data on my page.
function fb_share() {
FB.ui( {
method: 'feed',
name: "Facebook API: Tracking Shares using the JavaScript SDK",
link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, function( response ) {
// do nothing
} );
}
$(document).ready(function(){
$('button.share-btn').on( 'click', fb_share );
});
You can do the same thing in PHP if you have the publish_actions permission approved by Facebook. Both would produce the following result:
Source
I'm developing a referral application where users can refer their Facebook friends using a referral code. I'm using Facebook Javascript SDK. The problem I'm facing is that the send method works only for particular URLs, I mean if I change the users referral token in link parameter it gives me error 100 invalid link.
Here is the method :
FB.init({appId: app_id, xfbml: true, cookie: true});
FB.ui({
to : '********',
method: 'send',
name: 'Message',
link: 'example.com/emp?token=fAiS1ywL0lS8cUYtgLjk',
redirect_uri:'http://example.com'
});
For some particular link values it works fine but if the token is changed it fails with invalid link error.
I'm stuck with fixing this issue. Am I missing something?
Duplicate of Facebook FB.ui send dialog intermittently returns invalid link error.
For your second question related to the og:url meta, to simplify you have to provide the URL of the current page.
The Open Graph Protocol says:
og:url - The canonical URL of your object that will be used as its
permanent ID in the graph, e.g.,
"http://www.imdb.com/title/tt0117500/".
To understand how those metas work you can check how News websites implement this with the Facebook Object Debugger.
For example this link shows you the implemention of metas for a well-known newspaper website.
I use Facebook social comments plugin on my web page. I use event subscribe method to get the comments and save it to local database. Everything works perfectly well, except the response of comment link. Event subscribe code snippet:
window.fbAsyncInit = function(){
FB.Event.subscribe("comment.create", function(response){
alert(response.href);
});
};
Let's say I have the Facebook comments plugin on some page which url is:
http://mywebpage.com/index.php?article_id=10
So event subscribe returns the url which is equal to:
http://www.facebook.com/http://mywebpage.com/index.php?article_id=10
But that url does not exist... So what's wrong with that? How to get the correct url?
Your help would be appreciated.
The problem was with the PHP urlencode function that I used for encoding the page url before passing it to the Facebook plugin. So simply removed it and things got fixed.
I have an invite dialog on my page:
<a href="#" onclick="sendRequestToManyRecipients(); return false;" >xx</a>
<script language="javascript" type="text/javascript">
FB.init({appId : 'myappid', status : true, cookie : true, oauth: true});
function sendRequestToManyRecipients() {
FB.ui({ method: 'apprequests', message: 'xxx'},requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
</script>
When the invited user clicks the invite, he gets linked to the app, but I want the user to get redirected to a page like http://www.facebook.com/pages/xxx/xxx?sk=app_xxxx.
How can I do that?
That's not possible without some custom coding - the requests interface exists to drive traffic to apps on facebook, not to page tabs, there's no way to have Facebook send users to a tab when they accept the request.
You could just implement something on your canvas landing page that redirects users back to a page tab based on the information in the request as a workaround.
previous version of the apprequest which is request-form this was possible: How can I include a link in a FB app request?
However current version of apprequest : facebook guys lets only redirect to your app: https://apps.facebook.com/yourapp
#Vihay comments helps this custom workaround to redirect to page.
Hoping next version apprequests, facebook enables redirect to links within the fb app.
Agree with previous answers. Facebook will redirect to your app, which is just a Facebook wrapper around a page you can provide. That page can then use a client-side redirect to whatever page you'd like (like what Klout does).