Api.Notifications.Send() Error: Unknown method

Apr 12, 2010 at 8:03 PM

I am trying to send a notification to a specific user who has already connected and authorized with the offline_access permission (actually, the Application asks for all extended permissions to be granted, and they are). My code goes like this:

ConnectSession _connectSession = new ConnectSession("xxx", "xxx");
_connectSession.SessionKey = "xxx";
_connectSession.UserId = 100000000000005;
_connectSession.SessionSecret = "xxx";

if (_connectSession.IsConnected())
{
        Api _facebookAPI = new Api(_connectSession);
        user user = _facebookAPI.Users.GetInfo();
        bool isConnected = true;
        _facebookAPI.Notifications.Send("100000000000005", "Test notification!");
}

The last line fails and says "Unknown method."

I've tried other implementations, such as:

var message = @"[{""message"":""Your message goes here"", ""action_link"":{""href"":""http://apps.facebook.com/yourapp/page"", ""text"":""Friendly description for action hyperlink""}}]";
var newsparams = new Dictionary<string, string>();
newsparams.Add("method", "notifications.send");
newsparams.Add("uid", "100000000000005");
newsparams.Add("news", message);
_facebookAPI.SendRequest(newsparams);

But with that code, I will either get the same "Unknown method" error, OR, if I play around with adding/change parameters, I'll get a "The given key was not present in the dictionary." error. For example, modifying the above code to look like this will elicit the "The given key was not present in the dictionary." error:

var message = @"[{""message"":""Your message goes here"", ""action_link"":{""href"":""http://apps.facebook.com/yourapp/page"", ""text"":""Friendly description for action hyperlink""}}]";
var newsparams = new Dictionary<string, string>();
//newsparams.Add("method", "notifications.send");
newsparams.Add("uid", "100000000000005");
newsparams.Add("news", message);
_facebookAPI.SendRequest(newsparams);

Am I implementing this code wrong?

Apr 12, 2010 at 8:31 PM
Edited Apr 12, 2010 at 8:34 PM

I've spending more time on this, and based on the Facebook API reference (http://wiki.developers.facebook.com/index.php/Notifications.send) I have updated the code to resemble the following:

var notifyparams = new Dictionary<string, string>();
notifyparams.Add("api_key", "xxx");
notifyparams.Add("call_id", (DateTime.UtcNow - new DateTime(1970, 1, 1)).Seconds.ToString());
notifyparams.Add("sig", sig);
notifyparams.Add("v", "1.0");
notifyparams.Add("to_ids", "100000000000005");
notifyparams.Add("notification", "Testing notification");

_facebookAPI.SendRequest(notifyparams);

I beleive that this code is probably a more accurate implementation of what should be done. It appears the original code was for posting news feed notifications? At any rate, I no longer get the "Unknown method" error, I now am getting a "The given key was not present in the dictionary" error. Looking at the API page one could conclude that the following lines should also be included:

notifyparams.Add("session_key", "xxx");
notifyparams.Add("type", "app_to_user");

However, include these lines ens up with the "An item with the same key has already been added." error.

Apr 12, 2010 at 8:40 PM

Interesting.

Facebook discontinued support for this method March 1, 2010. Calling this method returns error code 3 -- Unknown method.

May 6, 2010 at 11:50 AM

Hi, does exist any workaround for that? Please help.

Thanks