1

I'm using Facebook C# API and I want to create a custom "Like" action, allowing the user to like objects outside of Facebook.

The user will be allowed to "Like" a custom object, like an Apple or a Book, and the app has to post this information in the user timeline.

I've tried

dynamic res = fb.Post("me/og.likes", new
                    {
                        message = "My first like  post using Facebook SDK for .NET"
                    });

But this gives me the following FacebookApiException exception

(Exception - #1611072) The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: object.

But if I try

dynamic res = fb.Post("me/og.likes", new
                    {
                        object="http://samples.ogp.me/226075010839791"
                    });

it doesn't even compile, since object is a reserved word on C#.

What should I do? Is it possible?

tkcast
  • 391
  • 3
  • 20

1 Answers1

3

Try escape using @:

dynamic res = fb.Post("me/og.likes", new
                    {
                        @object="http://samples.ogp.me/226075010839791"
                    });

EDIT: For other special characters you should be able to use a dictionary instead of a anonymous typed object:

var postInfo = new Dictionary<string, object>();
postInfo.Add("fb:explicitly_shared", "your data");

dynamic res = fb.Post("me/og.likes", postInfo);
Fabske
  • 2,106
  • 18
  • 33
  • Thank you! this works for object, but doesn't work for fb:explicitly_shared. Is there a way to escape this variable? – tkcast May 08 '13 at 16:54
  • When using the `new { ... }` you create an anonymous type with the specified properties. The `:` is not allowed in a property name so it's impossible to give a property the name "fb:explicitly_shared". – Fabske May 08 '13 at 17:13
  • I've edited my post to add more info, please check if it fix your problem. – Fabske May 08 '13 at 17:15