How to create an object on Facebook Data Store

Mar 19, 2009 at 1:35 PM
Hi,
am trying to create an object with data.createobject( ) which returns the  fbid  of  the created object .but when i  select  the object using FQL query, the result is no data found.

here's my code:
 Dictionary<string,string> wishlistvalue=new Dictionary<string,string>();

 string u_id =Master.API.uid.ToString(); 
wishlistvalue.Add("wishlist_id","2");
wishlistvalue.Add("user_id",u_id);

long wishlist_id = dt.createObject("wishess", wishlistvalue);

and here my FQL query:
SELECT user_id  FROM my_app.wishlist WHERE wishlist_id="2"

if anyone find error in my code ,please help.
thank you











     wishlistvalue.Add("wishlist_id","2");
                wishlistvalue.Add("user_id",u_id);
Oct 23, 2009 at 8:01 PM

unfortunately facebook datastore api does not provide a search method. And FQL can only query objects in datastore by "_id". When you lost the _id, you are screwed.

So you need to create an association between user and your wishlist first, in this way, you can associate the object you've created with your userid.

Association name "user_wishlist"

Association Type "one-way" (since you don't use wishlist to search for user I suppose)

obj 1 Alias "userid"

obj 1 type "Any"

obj 2 Alias "wishlist"

obj 2 type "wishlist" (select your wishlist object in the dropdown)

you can specify 1:1 or 1:many or many:many relationship using unique check boxes.

 

I see you are already getting the wishlist_id from the create object api call, so next you need to create the association between this wishlist_id and current user id.

API.data.setAssociation("user_wishlist",API.uid,wishlist_id,"",DateTime.Now);

The API ask for a string parameter named data before the time stamp, but I don't know where does it go or how can you get it back.

 

Hope this helps.