how to get Object ID for specific OG object? - facebook-graph-api

Action spec: how do I get the list of object id for specific object type . for example how do I get the list of "songs" in specific app/page. (I do know how to get list of actions and related objects)
In the example below I would like to give the user the option to "search" for all 'songs' in APP XXX
'action_spec':[{'action.type':'music.listens','song':388773468386}, 'APP':'XXXX']}" —

This returns all the information you need about a specific OG object
$facebook->api('/me/og.follows');
of course you need a valid token

Related

How can I find the fields available on a Node/Object without an Object ID?

If I have an ID for an Object in Facebook's Graph API, I can find out all the available fields on that Node Type by setting the parameter metadata=1.
For example, https://graph.facebook.com/v12.0/12345?access_token=censored&metadata=1 will return all the possible fields on the type of object that 12345 is. If 12345 is of type userleadgeninfo, then this query won't return details about object 12345, it will return all available fields I can request of any type of userleadgeninfo object.
But if I don't have an ID, how do I know what fields are available for an object type? For example, I can see from the metadata query on a userleadgeninfo object that one of the fields returned is retailer_item_id. However, my object 12345 doesn't have one of those, so I don't have an ID I can plug into the Graph API to get the metadata available on that type.

how to consider annotation groups in a ObjectConstructor

JMSSerializer comes with a Doctrine Object Constructor that does its job, but imagine an Entity with two properties forming a primary key:
UserBase
prop annotated with #ORM\Id and #Serializer\Groups({"1"})
- username
prop annotated with #ORM\Id and #Serializer\Groups({"2"})
- email
User extends UserBase
- other props here, no Id defined.
one property key is excluded by using group=1 while deserializing. The client potentially still sends both email and username. email should not be considered though.
Unfortunately, if you pass the two properties in the body, DoctrineObjectConstructor does not check if something is excluded by deserialization, so it tries to load the Entity from the DB, according to the two values:
foreach ($classMetadata->getIdentifierFieldNames() as $name) {
if ( ! array_key_exists($name, $data)) {
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
}
$identifierList[$name] = $data[$name];
}
What I would like to do is taking into account my annotated groups, so as to use the fallbackConstructor in case some property forming the identifier is missing.
As a starter this is a good point: I created my own service, by passing along the annotationDriver. Then, if the property forming the identifier is not associated with the actual group:
$classMetadata = $this->annotationDriver->loadMetadataForClass($metadata->reflection);
$classMetadata->properties //here groups are listed for each property
I can fall back to the fallbackConstructor, as if I had not passed that property in the body
...not so fast! My Entity User extends a UserBase where all my identifier are, so I should take into account hierarchy, possibly in a generic way.
Any hint?
Alright, JMSSerializer's Object Constructor does not consider serialization groups when determing identifiers. Hence, if you include all the IDs in your object, whether they are part of the actual context group or not, they will be counted in.
I created an alternative version of the Object in order to fix this misbehavior (at least for me). Hope it helps

How to correctly insert managed metadata term id using spservices updatelistitems

I have a sharepoint 2013 site that uses a managed metadata term set for navigation. Documents can be tagged with the managed metadata so they appear in whatever category or categories is appropriate for the document. I need to allow documents to be saved as favorites. I created a custom list that saves the file name and path but I can't get the managed metadata settings to save correctly. I am using spservices.UpdateListItems via javascript and pass the ids and terms in the valuepairs property of the call like so ;#. Although the method saves the record, it either does not save the term or it saves one completely unrelated. Does anyone have any further advice on how to do this?
$().SPServices({
operation: "UpdateListItems",
async: true,
batchCmd: "New",
listName: "UserFavorites",
valuepairs: [["Title", title], ["DocumentId", itemid],["AssetCategory", assetCategoriesString]],
completefunc: function (xData, Status) {
alert(Status + " -- " + xData.responseText);
}
});
Example of the assetCategoriesString variable contents:
"fc8d083a-fc5e-4525-8fef-04ba982d1633;#Print Publications"

FactoryGirl first created object used even when specify the second one

I can't really understand this. I have a course factory that I use to create two objects. When I visit the page for the Accounting course (as seen below) it displays the Marketing course page. However, if I use factory girl to create the accounting course first then it visits the correct page and the test passes.
describe "Course pages" do
subject { page }
let!(:published_course) { FactoryGirl.create(:course, title: 'Marketing') }
let!(:unpublished_course) { FactoryGirl.create(:course, title: 'Accounting') }
describe "displaying the right page" do
it "should display the accounting course page" do
visit course_path(unpublished_course)
expect(page).to have_content('Accounting')
end
end
end
It obviously visits the page of the object that is created first, but I don't know why or how to fix this.
Thanks,
Matt
course_path will generate the correct URL (i.e. containing the correct id param), but it's up to your controller to find the course for that id and pass it to your view. Instead, your controller/view must be conspiring to display the first course created.

Django, Tastypie and retrieving the new object data

Im playing a little bit with heavy-client app.
Imagine I have this model:
class Category(models.Model):
name = models.CharField(max_length=30)
color = models.CharField(max_length=9)
Im using knockoutjs (but I guess this is not important). I have a list (observableArray) with categories and I want to create a new category.
I create a new object and I push it to the list. So far so good.
What about saving it on my db? Because I'm using tastypie I can make a POST to '/api/v1/category/' and voilà, the new category is on the DB.
Ok, but... I haven't refresh the page, so... if I want to update the new category, how I do it?
I mean, when I retrieve the categories, I can save the ID so I can make a put to '/api/v1/category/id' and save the changes, but... when I create a new category, the DB assign a id to it, but my javascript doesn't know that id yet.
in other words, the workflow is something like:
make a get > push the existing objects (with their ids) on a list > create a new category > push it on the list > save the existing category (the category doesnt have the id on the javacript) > edit the category > How I save the changes?
So, my question is, what's the common path? I thought about sending the category and retrieving the id somehow and assign it to my object on js to be able to modify it later. The problem is that making a POST to the server doesn't return anything.
In the past I did something like that, send the object via post, save it, retrieve it and send it back, on the success method retrieve the id and assign it to the js object.
Thanks!
Tastypie comes with an always_return_data option for Resources.
When always_return_data=True for your Resource, the API always returns the full object event on POST/PUT, so that when you create a new object you can get the created ID on the same request.
You can then just read the response from your AJAX and decode the JSON (i dont know about knockout yet).
see the doc : http://readthedocs.org/docs/django-tastypie/en/latest/resources.html?highlight=always_return_data#always-return-data
Hope this helps