我开始使用 C# Trello API。我创建了简单的控制台应用程序,并首先运行它以获取访问令牌:
static void GetToken()
{
ITrello trello = new Trello("application key");
var url = trello.GetAuthorizationUrl("Test api", Scope.ReadWrite, Expiration.Never);
Process.Start(url.ToString());
}
Process.Start
打开我的默认浏览器实例,我允许访问该应用程序,并在下一页上获得了我的令牌。然后我硬编码令牌并尝试实现这个例子:
static void Main(string[] args)
{
ITrello trello = new Trello("application key");
trello.Authorize(token); // hardcoded token
Member me = trello.Members.Me();
Console.WriteLine(me.FullName);
}
但me
始终为空。我错过了什么?授权失败?如果是这样,我为什么不得到TrelloNet.TrelloUnauthorizedException
?
编辑:
过了一会儿,我在这个线程Json.NET
中发现了一些关于项目中包含的版本的建议,所以我更新了,现在我没有收到任何消息:Json.NET
TrelloNet.TrelloException
Member me = trello.Members.Me();
堆栈跟踪:
at TrelloNet.Internal.TrelloRestClient.ThrowIfRequestWasUnsuccessful(IRestRequest request, IRestResponse response)
at TrelloNet.Internal.TrelloRestClient.Request[T](IRestRequest request)
at TrelloNet.Internal.Members.Me()
at ConsoleApplication1.Program.Main(String[] args) in f:\Dropbox\Projects\TrelloManager\ConsoleApplication1\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()