所以我引用了 ebay.oauth.client 库,我试图用它来获取访问令牌,但它给了我一个错误。
非静态字段、方法或属性需要对象引用 'OAuth2Api.GetApplicationToken(OAuthEnvironment, IList)
这是我的代码
private string GetAuthTokenEbay()
{
bool isTestSite = true;
var url = (isTestSite) ? "https://api.sandbox.ebay.com" : "https://api.ebay.com"
var oAuthToken = "";
CredentialUtil.Load("config.yaml");
IList<String> scopes = new List<String>()
{
url + "/oauth/api_scope/buy.marketing",
url + "/oauth/api_scope",
url + "/oauth/api_scope/sell.inventory.readonly",
url + "/oauth/api_scope/sell.inventory"
};
//String state = "current-page";
OAuthEnvironment env = (isTestSite) ? OAuthEnvironment.SANDBOX : OAuthEnvironment.PRODUCTION;
oAuthToken = OAuth2Api.GetApplicationToken(env, scopes).AccessToken;
return oAuthToken;
}
好吧,我想通了,在我班级的顶部,我需要像这样的静态 oauthapi:
private static OAuth2Api api;
然后我需要像这样获取应用程序令牌
oAuthToken = api.GetApplicationToken(env, scopes).AccessToken.Token;
为了帮助所有遇到此类问题的用户,提供以下源自您的代码是很有用的...
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using eBay.ApiClient.Auth.OAuth2;
using eBay.ApiClient.Auth.OAuth2.Model;
private static OAuth2Api api = new OAuth2Api();
private string GetAuthTokenEbay()
{
bool isTestSite = true;
var url = (isTestSite) ? "https://api.sandbox.ebay.com" : "https://api.ebay.com";
var oAuthToken = "";
CredentialUtil.Load("config.yaml");
IList<String> scopes = new List<String>()
{
url + "/oauth/api_scope/buy.marketing",
url + "/oauth/api_scope",
url + "/oauth/api_scope/sell.inventory.readonly",
url + "/oauth/api_scope/sell.inventory"
};
//String state = "current-page";
OAuthEnvironment env = (isTestSite) ? OAuthEnvironment.SANDBOX : OAuthEnvironment.PRODUCTION;
oAuthToken = api.GetApplicationToken(env, scopes).AccessToken.Token;
return oAuthToken;
}