Delete the latest open graph read action - facebook

My app is able to create a read action successfully using the following code:
FB.api('/me/xyz:listen_to&song=<?=curPageURL()?>','post');
I need to give a link to delete the same story. My issue is, how do i get the id of the latest story i added s i can delete it. Can I get this id via php?
I got the following code from google search, but cannot figure out how to get the id that is passed in to the function.
function deleteAction()
{
FB.api(
'<?=$actionID ?>',
'delete',
function(response) {
alert('action deleted')
});
}

Related

Facebook: share custom story doesn't appear in the wall

I'm having problems with the way the custom story that I have is displayed on Facebook.
It's working fine but instead of publishing on the wall of the user, it appears in the Recent Activity section.
The steps I follow until now:
create the custom action 'Want'
set the 'Explicitly Shared' option on
run this code:
FB.api(
'me/mynamespace:want',
'post',
{
article: "https://developers.facebook.com/docs?locale=es_LA"
},
function (response) {
console.log(response);
}
);
Can anyone help me?
If you need more info let me know. Thanks
You don't set explicitly shared to on. You need to do that in the API call.

Adding a Facebook comment on a URL and have it displayed on user profile

I am creating a web application that displays a list of images taken from Flickr and I would like a user to login through Facebook and allow them to comment on those images. I was able to get the login/authentication working but I am now having trouble to enable a user to add a comment (as oppose to a Facebook 'post') on a Flickr image and have this activity show up on the user's Facebook profile/feed (i.e "John Smith commented on a link").
Here is what I have so far:
var fbCommentApi = '/me/myappname_ns:comment?access_token=' + fbUserToken + '&method=post' + '&picture=[WEBSITE_URL]' + selectedItemId;
FB.api(
fbCommentApi,
'post',
{ message: txtObj.value },
function (response) {
if (!response || response.error) {
alert("Sorry, there was a problem. Please try again later. [API]");
}
else {
alert("Thank you. Your comment will appear shortly");
hideCommentBox(txtObj);
}
}
);
The above code doesn't create a comment but instead it creates a post on the user's timeline with the URL attached. So when I try to retrieve comments for the WEBSITE_URL item through Facebook Graph...
'https://graph.facebook.com/comments/?id=[WEBSITE_URL]' + itemID
...I end up with empty data being returned.
I have an Action Type called 'Comment' in my Facebook app and that's the action I am using when trying to add the comment.
Thanks in advance and I look forward to your answers.
UPDATE 1: It seems now that if I use Facebook Graph this way.. graph.facebook.com/me/appname_ns:discuss?access_token=[TOKEN]&website=[URL]&met‌​hod=post
..it would just add an entry to the user's Activity box in their timeline, I didn't even pass a comment or message parameter to the URL as a query string parameter. That could be part of the problem.
UPDATE 2: According to another StackOverflow question, there seems to be no way to get a view of all actions done by all users, it has to be done per user (an API call per user). Therefore another way of handling this particular issue is to save the comments (or whatever action performed) to our own database.
Well, an Open Graph action is not a comment, even if you name it comment …
If you want a real Facebook comment, then either get a reference to an object that actually can be commented upon; or substitute comment with post/link post.

Error using news.reads Open Graph action

I'm trying out the new Open Graph actions to build functionality like the Washington Post Social Reader. I created OG pages of type "article" and posted "news.reads" action to them. I verified that the pages are valid OG objects using the OG debugger. And the user granted the publish_actions permissions.
I publish an action with an HTTP POST to:
https://graph.facebook.com/me/news.reads?article=((article link))&access_token=...
I get this error back from Facebook:
type = u'OAuthException', message = u'An unknown error has occurred.'
So I try the same action again, and this time I get this other error:
type = 'OAuthException'
message = '(#3501) User is already associated to a article object on a unique
action type Read. Original Action ID: ((action id))'
Where ((action id)) is a valid action ID, which I can verify by viewing:
http://graph.facebook.com/((action id))
Which gives me details about the action. I tried the above several times with different pages and different users, and it's the same flow: unknown error, duplicate action error. It looks like the action is being created, however:
I don't see it on the user timeline.
And I don't see it in the Activity Log.
What am I missing?
Note If I do the above using my own app-specific nouns and verbs, everything works as expected. But I'm interested in using the built-in nouns and verbs for better aggregation on users timelines.
If you action has not been approved by Facebook, it won't show up to end-users. Only those listed in the 'Roles' section of the Application Settings will be able to publish and see the actions in the Activity log (e.g. administrators, developers and testers).
Try testing the action with a Test User. Create a new test user from the 'Roles' page and login with them. See if the action is published and appears correctly on the Activity log.
Here's what I'm using to post video watches, you can try to do the same:
function postWatch()
{
FB.api('/me/video.watches' +
'?video=<?php echo $url; ?>','post',
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
//alert('Post was successful! Action ID: ' + response.id);
}
});
}
The built in Read action is defined as "unique" while your action type is not (see 'advanced' section in the action edit screen). You you can't submit Read with the same object url twice.

Uploading Image With Facebook JS SDK

I've put together a script, with the help of another SA post, but the issue I'm having is it's always returning error. When logging the error with console log it contains no properties so I can't determine why I am getting the error.
$(".add-image").click(function() {
FB.login(function(response) {
if (response.authResponse) {
var imgURL="http://farm4.staticflickr.com/3332/3451193407_b7f047f4b4_o.jpg";
FB.api('/album_id/photos', 'post', {
message:'Test',
url:imgURL
}, function(response){
if (!response || response.error) {
console.log(response);
} else {
alert('Post ID: ' + response.id);
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_stream'});
});
I've created the app. Added the API ID when including the Javascript.
When running I get a pop up asking me to log in, and it seems to log me in without problems. But it returns an error when checking for a response or response.error.
Any advice.
Not sure if this is still a problem for you, but I've been looking into the same thing recently and I believe that, for this type of upload, FB basically requires source to be the image data itself, not a URL to the image. (See the create photos section on https://developers.facebook.com/docs/reference/api/album/ - it indicates that the source paramater must be multipart/form-data.)
So you have a few workarounds:
1) You may be able to do it from JS if you can create a custom Open Graph Object. I haven't tried this yet, but https://developers.facebook.com/docs/opengraph/usergeneratedphotos/ looks like it expects a URL rather than the post data itself.
2) If the image is originating on the user's computer, you can create an HTML form that submits to FB and have the image go directly from the user to FB without ever hitting your server. This blog post shows an example of that: https://developers.facebook.com/blog/post/498/
3) If the image is originating in your system, you can do a POST from your server to FB that mimics the above form. If it's somewhere else online (such as Flickr), you can download it to your system first and then POST it to FB. You'll have to include an access_token in the request. I don't know what language / framework you're using on your server, but there's probably a library to make creating POST requests easier.

Select friends dialog

How can I select some friends using the Javascript API?
I'm working on a project where I want the user to select some friends which ID's I need, to display their profile images and names (among other things).
How do I do this?
Thank you in advance.
This is how I managed this...
$(".friendSelect").click(function () {
FB.ui({ method: 'apprequests', message: 'Choose 9 friends!' }, function (response) {
console.log(response) //The friends
});
});
This article explains how to get setup and using the Facebook javascript SDK. Once you've got that up and running you will want to get a FriendList object. From here you can then get a User object for each person in the FriendList.
You may want to try googeling 'javascript graph api tutorial' for code examples