Facebook JavaScript SDK Share Dialog: The Ultimate Tutorial
- berroughdoorfvedur
- Aug 13, 2023
- 6 min read
i have shared part of my code, which i tried to post video on facebook timeline.when i used this code, video get upload as a link. it will navigate to new tab and play when i click on that link.(my video type is mp4.)
Note the FB.ui call that will now occur after the user clicks on the button. The first argument of FB.ui is an object of properties to define what we want the SDK to do. We pass in a method, which is to share in this case. You also pass it an href, which in this case is the URL of the page the user is currently on. You could easily set that to a static URL as well, if you like. This FB.ui call will open the Facebook sharing dialog in a popup window and allow the user to choose how they want to share your page.
facebook javascript sdk share dialog
The second argument is a callback function that will be run after the user finishes with the sharing dialog popup. If the user cancels the dialog and chooses not to share your page, it will return undefined as the response. If the user successfully shares your page, it will return an empty array.
If set to true the share button will open the share dialog in an iframe on top of your website (For more information see Mobile Web Share Dialog. This option is only available for mobile, not desktop.
Facebook's Share Dialog requires an Application ID, so I added a field for it to the admin settings. If no App ID is provided, than the behavior of this module is unchanged. However, if an ID is provided, Facebook's Javascript SDK will be loaded, and a share dialog listener will be attached to every Facebook share link. When clicked this listener will launch the share dialog, overriding the default sharer.php implementation.
But, to clarify, the entire purpose of this module has always been to provide a simple solution to getting share links onto your site, not something that would require a lot of extra configuration to make work (ie: setting up a facebook application, etc) even if that is all relatively straightforward and easy, it shouldn't be necessary. That's all I'm personally going to say on the matter. :)
I have applied the patch, but when I click the button opens the popup and I can only POST on my facebook profile, I would like to be able to share and have the possibility to select where to SHARE (page, group, a friend's profile).I will load a picture to explain myself better (even if it is in Italian). The left block is the result of the patch, the right block is what I want.
We expected GIF upload on facebook to behave similarly as JPEG Image upload but Facebook does not allow GIF to be uploaded from API. We have to upload GIF to cloud server and then share that URL as a post.
Calling FB.login results in the JS SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.Before opening share dialog first check login status(FB.getLoginStatus) and if not login then first login (FB.login) otherwise share dialog open in popup window and in that if image size is large then popup window get flickered.
The DialogController handles events in pages that use the Facebook sharing dialogs such as the feed, send and share dialog. Create a DialogController.js under the js/controllers directory and add the following.
There is a plugin to help you integrate Facebook available on github. This simplifies the work of loading the Facebook javascript SDK. Just attach the plugin script lib/facebook-setup.js to an entity in your scene and listen for the fb:init event and you'll know the API is ready. More instruction are available on the github page.
Hi, I have a catalog page where i am showing a list of cars based on user search. Each car has its own image. There is a details page which takes url like DetailsPage.aspx?carid=335 and shows the details of car along its image. My requirement is that i want a facebook share button on the catalog page against each car. If there are 10 search results, there will be 10 share buttons one for each car. The share dialog should display the image of car being shared. My js code is
Drib, thanks a lot for that !I was reading this article a few days ago and everything worked fine. Today, when trying to implement it, I found out that something weird is happening with the images in the share dialog. They are sometimes shrinked by Facebook without reason. This happens on your quiz.htm page too. The funny story is that it seems this behaviour is linked to your FB account. When I try with my main FB account, everything is fine. When I switch to my test FB account, a square image is used.Anyone else is experiencing this ?
While playing with facebook old share.php I noticed few things, it will not work properly with canonical urls(Duplicate content avoiding option). When we try to pass url to the sharer.php it reads the meta content and look for the canonical url then parsing correct url as canonical url. So sharing image and description are different than you saw on the share dialog box.
I search on Google for this issue and finally found Facebook shows some wrong image and details in the dialog box but sharing time it parses the actual url. This means the sharer.php is not works like what we expected.Then I found an alternative way for share button with custom param.
Do not write code inside FB.ui() its facebook ui function call,So if you need to make a custom message or alert you can write insideafter this line,var share_capt = 'caption';alert("here");or after successfully share call back function if(response && response.post_id) alert("Success")elsealert("Failed ")
Enter your website or web page URL into the text input field where it says URL to share. From the Layout dropdown on the right, select your preferred share button layout. The most popular ones are box_count, button_count and button. The Mobile Iframe option controls whether you want the share dialog to be displayed in an Iframe or not.
What you need to do, as also explained on the code dialog, is to insert the JS SDK on your page (this will be done once, even for multiple share buttons on the same page) and place the button code where you want to display it.
In iOS, returns a Promise which will be invoked with an object containing action and activityType. If the user dismissed the dialog, the Promise will still be resolved with action being Share.dismissedAction and all the other keys being undefined. Note that some share options will not appear or work on the iOS simulator.
Only few lines of code we can easily implement this cool feature. I hope this tutorial will help you to drive traffic, increase facebook shares & improve search engine ranking for your websites. For this you need to create an Facebook App, register your website & get an App ID.
This code creates a share dialog that pops up over the application page when an action is performed and publishes an Open Graph action which can then be tied into the greater ecosystem and used to generate complex relationships and metric data.
Facebook share tool consists of a button added to the Social share panel. When the button is selected, the user is redirected to a sharing dialog box that is provided by a social service. The position of the button is fully managed by the Social share tool.
This works with API version 2.9+. Please note that using og.shares action_type, is not advised any more since it is not mentioned in the FB documentation and it doesn't properly display the large image. I now use og.likes. The small downside is the sentence like "John Doe likes the object on drib" near the top of share dialog and shared content on user wall.
If you run the app, you will see a share button. Clicking on this button will show a dialog containing the content you are about to share. You can change the preview according to your choice. Then, click on POST button to share the content. Finally, you will get output as shown above. 2ff7e9595c
Bình luận