开发者

Facebook C# SDK - Using a array in Api calls like in PHP

开发者 https://www.devze.com 2023-02-19 05:46 出处:网络
I\'m trying to use this code blo开发者_如何学编程ck of php in C#: $fb->api(array( \'method\' => \'events.invite\',

I'm trying to use this code blo开发者_如何学编程ck of php in C#:

 $fb->api(array(
    'method' => 'events.invite',
    'eid' => $event_id,
    'uids' => $id_array,
    'personal_message' => $message,
));

I've tried this:

            string[,] array = new string[3, 2];
            array[0, 0]= "method";
            array[0, 1] = "events.invite";
            array[1, 0] = "eid";
            array[1, 1] = IdEvent.ToString();
            array[2, 0] = "uids";
            array[2, 1] = "100000339376504";

            users = app.Api(array.ToString());

But without success, i'm receiving this error:

error = {"type":"OAuthException","message":"(#803) Some of the aliases you requested do not exist: system.string[,]"}

Can someone help me constructing this array? In this project i've the version 4 of Facebook C# SDK.

Thanks


The C# SDK does not support passing arguments as arrays. To clarify what you are doing, the PHP code and your C# array code are not functionally the same. The correct 'substitution' to the PHP code is a dictionary.

So to fix your code you will want to do this instead:

var parameters = new Dictionary<string, object>() {
    { "method", "events.invite" },
    { "eid", IdEvent },
    { "uids", "100000339376504" }
};
var users = app.Api(parameters);

Also, it is important to note that I am not using the Api(string path) override. The method that you should be calling is Api(IDictionary< string, object > parameters). They are two very different arguments. The correct use of the string override is something like:

var result = app.Api("me/friends");

Lastly, I would suggest you take a look at the Graph API and not the Rest API. The Rest API is being deprecated.

0

精彩评论

暂无评论...
验证码 换一张
取 消