ID value in Facebook Comments.Create callback - javascript

According to the Facebook documentation, the comment.create callback contains a Comment ID property:
{
href: "", /* Open Graph URL of the Comment Plugin */
commentID: "", /* The commentID of the new comment */
}
However I'm seeing that the callback contains a common ID property that doesn't change across the comments. For example, when i debug the callback I get an commentID value of "10150259852273822", but the value doesn't change for any comment left on that page. Below is a sample for the comments from the Graph API, notice the ID is the same across multiple comments, but its appended by a "_XXXX" number that appears to actually be the identifier.
{
"id": "10150259852273822_17973898",
"from": {
"name": "XXXXXX",
"id": "XXXXX"
},
"message": "newest comment",
"created_time": "2011-08-24T19:24:02+0000"
},
{
"id": "**10150259852273822**_17973932",
"from": {
"name": "XXXXX",
"id": "XXXXX"
},
"message": "brand newest comment.",
"created_time": "2011-08-24T19:25:40+0000"
}
Does anyone know how you can actually get the full identifier via the comment.create event? Or is there another field that can be used to predict the commonid_commentID format?

The comment ID from the callback is in fact the "post_fbid".
Here is how you can get the comment (and the data associated with it) :
FB.Event.subscribe('comment.create', function(response) {
var commentQuery = FB.Data.query("SELECT text, fromid FROM comment WHERE post_fbid='"+response.commentID+"' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url='"+response.href+"')");
var userQuery = FB.Data.query("SELECT name, uid FROM user WHERE uid in (select fromid from {0})", commentQuery);
FB.Data.waitOn([commentQuery, userQuery], function() {
// Do whatever you want with the data
console.log(commentQuery.value[0].text);
console.log(userQuery.value[0].name)
console.log(userQuery.value[0].uid);
});
});

What do you need/want the ID for. Perhaps we can come up with a better solution for what you need.
The common ID element is most likely (off the top of my head) specific to that comment form. And the additional bit is the "true" id of the comment as it were.
The full identifier of the comment is the whole element, your number that doesn't change and the appended element post the underscore.
Take a look here: http://developers.facebook.com/docs/reference/api/Comment/
And at the example graph URL.
The full string included underscored element is fully part of the comment ID

Related

Pull a full object from one value

I'm working on a ticket system, and I want to make a close ticket system, that will remove the ticket from the user, so I have my mongo array looking like this
{
"tickets": [{
"id": "cxZgqey2",
"subject": "fdgfdgdfgfdgfd",
"message": "gfdgfdgfdgdfg",
"ownerEmail": "soenmtherhg#gmail.com"
},
{
"id": "r4r-CnIC",
"subject": "dfdsfdsfsdfdsfdsf",
"message": "dsfdsfdfsdfdsfdsfdsfdsf",
"ownerEmail": "soenmtherhg#gmail.com"
}
]}
and I wanted to remove the entire object using only the id, how would I do this? (Using the npm module (not mongoose))
You can use the filter function in arrays and delete it passing the relevant id for that and also you can check loadash.

Get all doc data from Cloudant as opposed to id, key, value

Trying to query against my db to get all docs with all info. The db.list functionality gets the overview of the docs but does not return all the data for the docs. Currently have to get the high level data then loop through the rows and query each individual doc. There must be a better way...
Is there a way to get all docs with the full set of info for each doc?
getting:
{
"id": "0014ee0d-7551-4639-85ef-778f74365d05",
"key": "0014ee0d-7551-4639-85ef-778f74365d05",
"value": {
"rev": "59-4f01f89e12c488ba5b8aba4643982c45"
}
}
want:
{
"_id": "14fb92ad75b8694c05b98d89de6e9b2d",
"_rev": "1-6067c00b37a18ad8bab6744d258e6439",
"offeringId": "ae0146696d1d3a90fe400cc55a97a60e",
"timestamp": 1464165870848,
"srcUrl": "",
"score": 9,
...
}
The repository you linked to for nano looks like an outdated mirror. The official repository includes documentation for db.list which also includes a params object. I would double-check your version of nano, but I would guess you already have a more recent version.
You can simply add { include_docs: true } as the first argument to db.list and alongside id, key and value, you'll get a doc property that has the entire document.

MongoDb: Find the generated id of the inserted child on parent save

If I have a document representing a post with comments that looks like this:
{
"_id": "579a2a71f7b5455c28a7abcb",
"title": "post 1",
"link": "www.link1.com",
"__v": 0,
"comments": [
{
"author": "Andy",
"body": "Wish I had thought of that",
"_id": "579a2a71f7b5455c28a7abcd",
"upvotes": 0
},
{
"author": "Jim",
"body": "Just a comment",
"_id": "579a2a71f7b5455c28a7abcc",
"upvotes": 0
}
],
"upvotes": 5
}
In the calling (javascript) code, I add a new comment, by pushing to the post.comments array, then save the post using .save with a callback. In the save callback, I want to get the generated _id of the new comment I just saved. How do I do this?
I've got the parent post document in the callback, of course, but that's not useful as I can't tell which comment was just inserted.
Is there another document method or an alternate form of the .save callback to deal with my situation?
Or do I have to just follow what I'd usually do and generate a unique id on the comment myself before the save?
EDITED: I'm using Mongoose, sorry, forgot to say!
You did not specifically tell, but I assume you use Mongoose because standard MongoDB will not add an _id property to subdocuments.
As mentioned in the Mongoose documentation regarding adding sub-documents, you can use the following code example:
var Parent = mongoose.model('Parent');
var parent = new Parent;
// create a comment
parent.children.push({ name: 'Liesl' });
var subdoc = parent.children[0];
console.log(subdoc) // { _id: '501d86090d371bab2c0341c5', name: 'Liesl' }
subdoc.isNew; // true
parent.save(function (err) {
if (err) return handleError(err)
console.log('Success!');
});
Instead of parent.children[0] you have to use parent.children[parent.children.length - 1] to access the inserted element, though.
I'd assume the item you pushed on the array would be the last one, but that wouldn't work in a multi user system.
Also you could make a comparison against the author and comment fields, though this seems like a lot of trouble, and with just the author and the comment text, you might not be assured a match.
Finally, you could also create the object id and assign it to the comment, then save it. You do that like this:
var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId();
That's what I would do.

Retrieve the value from a JSONP formatted data object

Just when I think I've got he hang of identifying an element in an object, I run into a scenario that I cannot seem to get the value I want.
This part works and the data returned is correct: I have a map and when I attempt to identify a building on the map, I receive the following json object (this has been shortened for readability but in real life, its properly formatted): The function MapClick(queryResults) is called when the map is clicked.
dojo.io.script.jsonp_dojoIoScript19._jsonpCallback({
"results": [
{
"layerId": 5,
"layerName": "Building",
"value": "Name of item clicked",
"displayFieldName": "name",
"attributes": {
"ID": "123",
"name": "Name of item clicked",
"Variable1": "Some bit of information",
"Variable2": "Some other bit of information",
...
...
All I'm trying to do is return either the results[0].value OR results[0].attributes.name which in this example should bring back "Name of item clicked". The layerId, layerName, value, and displayFieldName are the "common most accessed data" so they are returned but the same information is also found within the attributes.
I've tried console.log(results[1].attributes.name); and console.log(results) with no success.
Turns out the name of the function handling the MapClicked is queryResults was needed so the correct answer is: queryResults[0].value and when you see open brackets [, you can be sure you will need [ some number ] (e.g. queryResults[0].value or queryResults[99].someothervariable. Or at least I think this is a correct statement.

Google tasks update error

I am attempting to update a task with the following code:
function updtsk(task,id)
{
var url = 'https://www.googleapis.com/tasks/v1/lists/#default/tasks/'+id;
var req = {
'method': 'PUT',
'headers': {
'Content-type': 'application/json'
},
'body': JSON.stringify(task)
};
var addDone = function(resp, xhr) {
if (xhr.status != 200) {
notifyFailure('Couldn\'t update task.', xhr.status);
return;
}
//notifySuccess(task['title']);
}
oauth.sendSignedRequest(url, addDone, req);
}
I get the following error however:
"{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
"
The update body is this:
{
'title': $(this).val()
};
I am using the chrome_ex_oauth api and could use some help.
Try passing the 'id' key/value pair together with the title information you are already sending.
I had this same problem, even using the API explorer. There's no documentation to indicate this is a required parameter, especially since it is included in the URL. Once I added id, it worked properly.
It's possible you need to include additional fields in the update.
The documentation here: http://code.google.com/apis/tasks/v1/reference.html#resource_tasks appears to indicate the status property is not optional (the other mutable fields are listed as optional in their descriptions). You may also need to include the kind property with the static value indicated there.
In Google Task API for updating any TaskList Task:
First we have to get task with use of TaskList Id and Task Id
Second step change/update in task and again update that task.
Hope this is helpful for you.
I read these answers several times, but only saw what I thought I already knew, which was wrong. The documentation for insert/update/etc. states
POST https://www.googleapis.com/tasks/v1/lists/tasklist/tasks
It is the id of the tasklist being modified (e.g. something like "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow") and not the title of the tasklist e.g. "My Task List" that needs to be passed in the POST request header, e.g.
POST https://www.googleapis.com/tasks/v1/lists/MTA1MjEpoqwdNTMzMjAzo349YDA6MDow/tasks
You can find the id of the list by doing a tasklists 'list' query.
GET https://www.googleapis.com/tasks/v1/users/#me/lists
which returns, e.g. something like this:
{
"kind": "tasks#taskList",
"id": "MTA1MjEpoqwdNTMzMjAzo349YDA6MDow",
"title": "My Task List",
"updated": "2019-03-15T21:21:03.000Z",
"selfLink": "https://www.googleapis.com/tasks/v1/users/#me/lists/MTA1MjE0Njc5NTMzMjA1NDk0NDA6MDM1NDgwMjIxODgyMjcyODow"
}
You can see the tasklist id in the response, which can then be used in the POST to modify the desired tasklist.
Answers to this question have been posted, but none with explicit examples. Hopefully this example will help someone get past this newbie kind of problem.

Categories

Resources