YelpSharp返回错误“其他信息:没有可用的OAuth信息。”

时间:2014-02-23 22:01:21

标签: c# yelp

我正在使用@ JustinBeckwith的项目YelpSharp。我有配置文件,我用我自己的Yelp API密钥编辑它。我实际上还没有写过一行代码 - 我正在使用YelpSharp附带的测试。

在Windows 7 x64上使用VS2013。

不幸的是,当我尝试运行他的(Justin's)测试时,我遇到了标题中提到的错误:

An unhandled exception of type 'System.InvalidOperationException' occurred in     
BusinessResearcher.exe

Additional information: No OAuth info available.  Please modify 
Config.cs to add your YELP API OAuth keys

这里(或here - 代码与原始代码相同)是我的配置文件(我已经编辑了我的密钥):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YelpSharp;

namespace BusinessResearcher
{
    class Config
    {
        private static Options _options;

        /// <summary>
        /// return the oauth options for using the Yelp API.  I store my keys in the environment settings, but you
        /// can just write them out here, or put them into an app.config file.  For more info, visit
        /// http://www.yelp.com/developers/getting_started/api_access
        /// </summary>
        /// <returns></returns>
        public static Options Options
        {
            get
            {
                if (_options == null)
                {
                    // get all of the options out of EnvironmentSettings.  You can easily just put your own keys in here without
                    // doing the env dance, if you so choose
                    _options = new Options()
                    {
                        AccessToken = Environment.GetEnvironmentVariable("my_code_is_hidden_here_from_stackoverflow", EnvironmentVariableTarget.User),
                        AccessTokenSecret = Environment.GetEnvironmentVariable("my_code_is_hidden_here_from_stackoverflow", EnvironmentVariableTarget.User),
                        ConsumerKey = Environment.GetEnvironmentVariable("my_code_is_hidden_here_from_stackoverflow", EnvironmentVariableTarget.User),
                        ConsumerSecret = Environment.GetEnvironmentVariable("my_code_is_hidden_here_from_stackoverflow", EnvironmentVariableTarget.User)
                    };

                    if (String.IsNullOrEmpty(_options.AccessToken) ||
                        String.IsNullOrEmpty(_options.AccessTokenSecret) ||
                        String.IsNullOrEmpty(_options.ConsumerKey) ||
                        String.IsNullOrEmpty(_options.ConsumerSecret))
                    {
                        throw new InvalidOperationException("No OAuth info available.  Please modify Config.cs to add your YELP API OAuth keys");
                    }
                }
                  return _options;
            }
        }
    }
}

以下是我的Form1.cs按钮(点击事件)中的方法:

        Yelp y = new Yelp(Config.Options);
        var task = y.Search("coffee", "seattle, wa").ContinueWith((searchResults) =>
        {
            foreach (var business in searchResults.Result.businesses)
            {
                Console.WriteLine(business.name);
            }
        });

1 个答案:

答案 0 :(得分:0)

固定。

@JustinBeckwith已经说过你可以把你自己的钥匙“没有做环境舞蹈”,但我不知道怎么做。我尝试将其作为变量输入,但它一直说, is expected。显然我必须将它们全部添加到一行。

要解决它,请更改此命令(来自config.cs):

                AccessToken = Environment.GetEnvironmentVariable("6iIPqqCxpUTflkTyjBKb0rtUPbnW-z8l", EnvironmentVariableTarget.User),
                AccessTokenSecret = Environment.GetEnvironmentVariable("rxA6_mwQwCFjqYoOajs566e8UUw", EnvironmentVariableTarget.User),
                ConsumerKey = Environment.GetEnvironmentVariable("40o625RXM9Cylazmjx8F1A", EnvironmentVariableTarget.User),
                ConsumerSecret = Environment.GetEnvironmentVariable("UfOwDu-qRbCLHJFaQ83xEf1Hbgg", EnvironmentVariableTarget.User)

用这个:

AccessToken = "access_token_here", AccessTokenSecret = "AccessTokenSecret_key", ConsumerKey = "ConsumerKey_key", ConsumerSecret = "ConsumerSecret_key",};