BingAds getting invalid_grant The user or administrator has not consented to use the application with ID when trying to get refresh token

Farukh Khan 1 Reputation point
2022-08-11T12:07:45.347+00:00

Getting this error while trying to get refreshtoken :

System.Private.CoreLib: Exception while executing function: func-bing-ads. Microsoft.BingAds: Couldn't request OAuth AccessTokens. Please check the Details property for more information. Details: invalid_grant - XYZ: The user or administrator has not consented to use the application with ID 'xyz' named ' Bing Ads Extractor'. Send an interactive authorization request for this user and resource.

Code:

        //the following gets the auth and refresh token  
        var apiEnvironment = ApiEnvironment.Production;  
        var oAuthDesktopMobileAuthCodeGrant = new OAuthDesktopMobileAuthCodeGrant(  
            _config["clientId"],  
            apiEnvironment  
        );  


             var additionalParams = new List<KeyValuePair<string, string>>()  
            {  
                new KeyValuePair<string, string>(  
                    "client_secret",  
                    _config["bing:clientSecret"])  
            };  

        var str = oAuthDesktopMobileAuthCodeGrant.GetAuthorizationEndpoint();  

        var auth = await oAuthDesktopMobileAuthCodeGrant.RequestAccessAndRefreshTokensAsync(accesstokenAsString , additionalParams);// Error Returns from here  
Microsoft Advertising API
Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
399 questions
0 comments No comments
{count} votes