0

我正在使用@JustinBeckwith 的项目YelpSharp。我有配置文件,并使用自己的 Yelp API 密钥对其进行了编辑。实际上,我还没有写过任何代码——我正在使用 YelpSharp 附带的测试。

在 Windows 7 x64 上使用 VS2013。

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

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

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

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);
            }
        });
4

1 回答 1

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",};
于 2014-02-24T08:03:15.563 回答