简体   繁体   中英

Instagram Access Token Windows Store App C#

I want to get access token from instagram api in windows store app

Here's my code:

string endURL = "ms-app://..";  string clientID = "..";
Uri endUri = new Uri(endURL);
string startURL = "https://api.instagram.com/oauth/authorize/?"
                + "client_id=" + clientID
                + "&redirect_uri=" + endURL
                + "&response_type=code";
try
{
    WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync
        (WebAuthenticationOptions.None, startUri);
    if (result.ResponseStatus == WebAuthenticationStatus.Success) {
        string token = webAuthenticationResult.ResponseData;
}
catch(Exception) { }

I get that error:

The specified protocol is unknown. (Exception from HRESULT: 0x800C000D)

Why don't you directly use InstaAPI github & codeplex ?


List<Scope> scopes = new List<Scope>() { Scope.basic };
InstaConfig config = new InstaConfig("CLIENT_ID", "CLIENT_SECRET", "REDIRECT_URI", scopes);

// use this to redirect user for authenticating your application
String AuthenticationUriString = config.GetAuthenticationUriString(); 

OAuth oauth = new OAuth(config, "CODE_ATTACHED_WITH_REDIRECTEDURI_AFTERSUCCESSFUL_AUTHENTICATION");
AuthUser user = oauth.GetAuhtorisedUser();

Console.WriteLine(user.AccessToken);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM