private string CreateAuthLink() { var scopes = new List <OAuth.Scope>(); scopes.Add(OAuth.Scope.Likes); ////scopes.Add(OAuth.Scope.Comments); return(OAuth.AuthLink(_config.OAuthUri + "/authorize", _config.ClientId, _config.RedirectUri, scopes, OAuth.ResponseType.Code)); }
public string GetAccessLink(InstagramConfig config) { var scopes = new List <OAuth.Scope>(); scopes.Add(OAuth.Scope.Basic); scopes.Add(OAuth.Scope.Public_Content); // scopes.Add(InstaSharp.OAuth.Scope.Comments); var link = OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, OAuth.ResponseType.Code); return(link); }
public async Task <string> GetToken() { try { OAuth auth = new OAuth(); var linkGet = auth.AuthLink(); if (!String.IsNullOrEmpty(linkGet)) { //Call de First URL and recover cokies (mid, scrToken) to use in the POST string secondLink = await this.GetFormAndRecorverCookies(linkGet); if (!String.IsNullOrEmpty(secondLink)) { //Post Form with credencial and recover cookies and the last Url to get Token string thirdLink = await this.PostFormWithCredencials(secondLink); if (!String.IsNullOrEmpty(thirdLink)) { //Call the last URL to get Token return(await GetToken(thirdLink)); } else { return(string.Empty); } } else { return(string.Empty); } } else { return(String.Empty); } } catch { return(string.Empty); } }
public async Task <ActionResult> Index() { RepositoryDataAccessInstagram repo = new RepositoryDataAccessInstagram(); var auth = new OAuth(); OAuthResponse oauthResponse; var dataAccess = repo.GetIsValid(); if (dataAccess != null) { oauthResponse = dataAccess.Map <DataAccessInstagram, OAuthResponse>(); } else { LogonInstagram logon = new LogonInstagram(); var token = await logon.GetToken(); oauthResponse = await auth.RequestToken(token); if (oauthResponse != null) { var data = oauthResponse.Map <OAuthResponse, DataAccessInstagram>(); if (data != null) { repo.Save(data); } } } if (oauthResponse == null) { return(Redirect(auth.AuthLink())); } else { return(View(oauthResponse.User)); } }
/// <summary> /// User needs to authenticate first. /// </summary> /// <param name="strClientId"></param> /// <param name="strSecretId"></param> /// <param name="strRedirectUrl"></param> public static async void Authorization(string strClientId, string strSecretId, string strRedirectUrl) { InstagramConfig config = new InstagramConfig(strClientId, strSecretId, strRedirectUrl); var instasharp = new OAuth(config); var scopes = new List <OAuth.Scope>(); scopes.Add(OAuth.Scope.Likes); scopes.Add(OAuth.Scope.Comments); scopes.Add(OAuth.Scope.Basic); scopes.Add(OAuth.Scope.Follower_List); scopes.Add(OAuth.Scope.Public_Content); scopes.Add(OAuth.Scope.Relationships); var link = OAuth.AuthLink(config, scopes, OAuth.ResponseType.Token); var startUri = new Uri(link); var endUri = new Uri(GlobalVariable.InstagramRedirectURI); string code = string.Empty; try { var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri); if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { code = webAuthenticationResult.ResponseData.Remove(0, 37); GlobalVariable.InstagramAccessToken = code; } } catch (Exception ex) { Debug.WriteLine("Exception at Authenticate(): " + ex.Message); } //if (!string.IsNullOrEmpty(GlobalVariable.InstagramAccessToken)) //{ // await GetSelf(); //} }