我正在使用@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);
}
});