I am using @JustinBeckwith's project YelpSharp. I have the config file and I have edited it with my own Yelp API keys. I actually have not wrote a single line of code yet - I am using the tests included with YelpSharp.
Using VS2013 on Windows 7 x64.
Unfortunately when I try to run his (Justin's) tests I run into the error mentioned in the title:
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 (or here - the code is the same as the original) is my config file (I have edited out my 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;
}
}
}
}
And here is the method from my Form1.cs
button(click event):
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);
}
});
Fixed.
@JustinBeckwith has said that you can put your own keys "without doing the env dance", but I was not sure how to do it. I tried to type it in as a variable, but it kept saying that , is expected
. Apparently I have to add them all on one line.
To solve it change this (from 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)
with this:
AccessToken = "access_token_here", AccessTokenSecret = "AccessTokenSecret_key", ConsumerKey = "ConsumerKey_key", ConsumerSecret = "ConsumerSecret_key",};