1

我正在尝试从 Xamarin.iOS 应用程序中调用 vimeo REST API,但我不断收到 401:The oauth_signature passed was not valid.

这是代码:

public async Task GetAll (string userId)
{
    var request = OAuth1.CreateRequest (
        "GET",
        new Uri ("http://vimeo.com/api/rest/v2"),
        new Dictionary<string, string> {
            {"user_id", userId},
            {"format", "json"},
            {"method", "vimeo.video.getAll"}
        },
        CONSUMERKEY, CONSUMERSECRET, TOKENSECRET);

    var response = await request.GetResponseAsync ();
    using (var stream = response.GetResponseStream ())
    using (var reader = new StreamReader (stream, System.Text.Encoding.UTF8)) {
        Console.WriteLine (request.RequestUri);
        Console.WriteLine(reader.ReadToEnd ());
    }
}

该请求看起来是一周形成的,但无论如何它都失败了。有什么提示吗?

4

1 回答 1

3

通过比较生成的 BaseStringXamarin.Authhttp://oauth.googlecode.com/svn/code/javascript/example/signature.html生成的 BaseString,我发现oath_token缺少该参数。

我通过手动添加解决了我的问题:

public async Task GetAll (string userId)
{
    var request = OAuth1.CreateRequest (
        "GET",
        new Uri ("http://vimeo.com/api/rest/v2"),
        new Dictionary<string, string> {
            {"user_id", userId},
            {"format", "json"},
            {"method", "vimeo.video.getAll"},
            {"oauth_token", ACCESSTOKEN},
        },
        CONSUMERKEY, CONSUMERSECRET, TOKENSECRET);

    var response = await request.GetResponseAsync ();
    using (var stream = response.GetResponseStream ())
    using (var reader = new StreamReader (stream, System.Text.Encoding.UTF8)) {
        Console.WriteLine (request.RequestUri);
        Console.WriteLine(reader.ReadToEnd ());
    }
}
于 2013-10-04T12:29:58.973 回答