How to access FB share in BB10? - blackberry-webworks

I have tried to share on facebook But was not able to share anything.
The code that i have used is:-
In Javascript
FB.init({
appId: 'some id',
cookie: true,
status:true,
xfbml:true,
oauth:true
});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'http://www.example.com',
picture: imageToShare,
name: 'name',
caption: 'This Link is Shared through the some application.',
description: ''
};
function callback(response) {
//document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
In config file
<access uri="http://connect.facebook.net" />
Thanks in advance.

If all you want to do is share something from your app to Facebook you can do this quite easily using Cards.
I wrote a blog post on this here: http://devblog.blackberry.com/2013/02/twitter-and-facebook-cards/
Basically, you're using the BlackBerry invocation framework to invoke the Card, and passing some data to that card.
function invokeFacebook() {
blackberry.invoke.invoke({
target: "Facebook",
action: "bb.action.SHARE",
type: "text/plain",
data: "I’m eating tacos with Alex."
}, onSuccess, onError);
}
If you want to share an image you would just swap out the 'data' attribute with:
uri: 'file://' + pathToFile,
There's also a sample app on our GitHub repo: https://github.com/ctetreault/BB10-WebWorks-Samples/tree/master/invoke/invoker

Related

FB feed method does not work as it used to when sharing image and url

I am trying to share image from FB app, using send dialog like I am doing for past few years.
var obj = {
method: 'feed',
link: 'https://www.facebook.com/pages/TESTPAGE?sk=app_XXXXXXXXXXXXXX&app_data=share|10',
caption: '',
name: 'Title for share',
description: 'description fort share',
picture: IMG_URL
};
I have provide 2 screenshots
when I click on share button inside of app
what I keep getting on my profile wall.
Until few months ago, FB would show data from feed method, but now, feed is acting just like share method: it shares url, without image and labels I sent through feed dialog.
All I want is to share image from app, and url of that image should point to app url.
Any suggestions?
I came across this issue from yesterday. The issue only happens when you pass in the FB app link url to the Link option. The works fine with the images as long as the link url is not anything related to FB.
So the workaround I found was to get a shortened URL from google and passed it instead of the normal app link.
FB.ui({
name: 'temp',
method: 'feed',
picture: '',
link: '{shortened url}',
caption: 'temp',
description: 'temp',
redirect_uri: 'any url'
}, function(response){
});
You can try this code to share image from FB app:
FB.ui(
{
method: 'feed',
display: 'popup', // must be one of "popup", "dialog", "iframe", "touch", "async", "hidden", or "none"
name: 'Title for share',
description: 'Description for share',
caption: 'www.facebook.com/YourFbPage/app_xxxxxxxxxxxxxxxxxxx',
link: 'http://PathToYourDomain.com/Folder/',
picture: 'http://PathToYourDomain.com/Folder/img/img-1200x627.jpg',
},function(response) {
if (response && response.post_id) {
// alert('Post was published.');
} else {
// alert('Post was not published.');
}
}
);
Best and good luck!
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object : {
'og:url': str_href,
'og:title': 'title', //galleryItem.title,
'og:description': 'desc', //galleryItem.description,
'og:og:image:width': '2560',
'og:image:height': '960',
'og:image': str_picture //BASE_URL + '/images/works/galleries'
}
})
});

Facebook Feeds Popup Dialog Does Not Close

Using the FB.ui to publish a feed with parameter display:popup. When a user selects the "Cancel" or after "Share", the web site specified in the 'redirect_uri' parameter is displayed within the popup. The Facebook documentation states that the popup dialog should be dismissed when the buttons are cancelled.
Here is my code. What am I doing wrong?
<script src='http://connect.facebook.net/en_US/all.js'></script>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: my APP ID, status: true, cookie: true,
xfbml: false, channelUrl: 'MY URL/fb-channel.html'
});
};
function fbShare(title, fbSiteUrl, fbThumbnailUrl, fbSiteDescription) {
var publish = {
method: 'feed',
name: title,
caption: 'MY CAPTION',
description: fbSiteDescription,
picture: fbThumbnailUrl,
link: fbSiteUrl,
redirect_uri: 'MY WEB SITE URL',
actions: [
{ name: 'MY WEB SITE Name', link: 'MY WEB SITE URL' }
],
display: 'popup'
};
function callback(response) {
}
FB.ui(publish, callback);
}
</script>

redirect user after share facebook

i want to redirect users to a specific page after they share on facebook, i have found a good answer here at:
redirect user after facebook share and publish
here's the script
<script type="text/javascript">
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
function share_me() {
FB.ui({
method: 'feed',
app_id: 'YOUR_APP_ID',
link: 'SHARE_URL',
picture: 'PIC_URL',
name: 'SHARE_NAME',
caption: 'SHARE_CAPTION',
description: 'SHARE_DESCRIPTION'
},
function(response){
if(response && response.post_id) {
self.location.href = 'SUCCESS_URL'
}
else {
self.location.href = 'CANCEL_URL'
}
});
}
</script>";
<div onclick="share_me()">Share</div>
but when i used the script ,there's no redirect at all, even if the user click "cancel"
please help me with this as am searching for a method like this since 1 week!
Try using another javascript function for redirecting like window.location = "YOUR_PAGE"

facebook api with private message multiple to (friends)

I development facebook private message for invite with facebook api.
<script>
FB.init({ appId: 'xxxxxxxxxx', xfbml: true, cookie: true });
FB.ui({
method: 'send',
to: ['1736383768','590528674'],
// picture: 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
//Can be page, popup, iframe, or touch.
display: 'popup',
name: 'yyyyyy',
link: '<%=Request.QueryString["link"]%>'
});
</script>
but adds only the first mate.
how to multiple friends send private message ?
var publish =
{
method: 'stream.publish',
message: 'Some kind of test',
uid: uid,
attachment: {
name: 'Test',
caption: 'Facebook API Test',
description: ('Sure hope it worked!'),
href: 'http://www.test.com/',
media: [
{
type: 'image',
href: 'http://test.com/',
src: 'http://test.com/image.jpg'
}
]
},
action_links: [
{ text: 'Your text', href: 'http://www.test.com/' }
],
user_prompt_message: 'Share your thoughts about test'
};
publish.target_id = friendID;
FB.ui(publish);
publish.target_id = friendID;
FB.ui(publish);
return false;
You should not use stream.publish.
As said by facebook : "We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the feed connection of the User object"
So, now you have the send and feed methods left.
You cannot fill the send method with more than one user id (you can only if you are whitelisted by facebook, but I'm not quite sur how to do this , I would not count on it either).
You can use the feed method to post on many user's friends wall with something like this
FB.api('/USERID/feed', 'post', {
name:postName,
link:postLink,
picture:postPicture,
description:postDescription,
message:postMessage
}, function (postResponse) { //DO SOMETHING HERE });
But doing it, you are taking the risk of your app being deleted by facebook if someone flag it as spam.
As far as I know, sending messages to multiple friends via an App is considered bad/spam by facebook so they do not allow this anymore.
You still can Invite as many friends as you want via the App request dialog (method apprequests) but I'm not sure this is what you want.

Feed Dialog not working on some browsers

Hi guys I have a weird problem with de feed dialog.
It works pefect on Firefox, but when I try to use it on IE or Chrome I got this error "An error occurred. Please try later"
I have tried to fix it but I can't. Can you help me please.
This is the code i'm using to call the dialog.
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_GB/all.js'></script>
<a href="#" onclick='postToFeed(); return false;'>Post Feed</a>
<script>
FB.init({appId: "xxxx", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'http://apps.facebook.com/xxxx',
picture: 'xxxx',
name: 'xxxx',
caption: 'xxxxx',
description: 'xxxxx',
properties: [{text: 'xx', href: 'xx'},],
actions: [{name: 'xx', link: 'xx'}],
};
function callback(response) {
document.getElementById('msg').innerHTML = "Well Done!!";
}
FB.ui(obj, callback);
}
</script>
</script>
A couple of things to try:
1: It could possibly be as simple as the rogue comma in your code here after actions:
actions: [{name: 'xx', link: 'xx'}],
Try removing that, however Chrome should better handle that, but that would have caused an issue with IE!
2: Use the Console to see if any errors are thrown.
3: Add oauth: true to your init statement like so:
FB.init({appId: "xxxx", status: true, cookie: true, oauth: true});
4: Remove the parameters in the call, and add them back in one by one after testing it works with each addition: start with:
var obj = {
method: 'feed',
link: 'http://apps.facebook.com/xxxx',
picture: 'xxxx',
name: 'xxxx',
caption: 'xxxxx',
description: 'xxxxx'
};