使用Xamarin.Auth在vimeo上的OAuth签名无效

时间:2013-10-02 09:06:44

标签: c# oauth xamarin.ios vimeo xamarin.auth

我正在尝试从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 ());
    }
}

请求看起来是一周形成的,但无论如何它都会失败。任何提示?

1 个答案:

答案 0 :(得分:3)

通过比较Xamarin.Auth生成的BaseString和http://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 ());
    }
}