skip to Main Content

So I have referenced the ebay.oauth.client library and I’m trying to use it to get the access token but it’s giving me an error.

An object reference is required for the non-static field, method or property ‘OAuth2Api.GetApplicationToken(OAuthEnvironment, IList)

Here is my code

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

2

Answers


  1. Chosen as BEST ANSWER

    Ok I figured it out, at the top of my class I needed the static oauthapi like so:

    private static OAuth2Api api;
    

    then I needed to get the application token like so

    oAuthToken = api.GetApplicationToken(env, scopes).AccessToken.Token;
    

  2. in order to help all users of this kind of problem, it is usefull to give the code as below orinigating from yours…

    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;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search