public static string getRelatedInsta(string searchtag) { List <string> list = new List <string>(); List <string> listz = new List <string>(); var clientId = "769313f94a484b869c8e3ec8f0f44936"; var clientSecret = "9054ca26824d4a0cab5e09964434279d"; var redirectUri = "http://*****:*****@SG/default.aspx"; var config = new InstaSharp.InstagramConfig("https://api.instagram.com/v1", "https://api.instagram.com/oauth", clientId, clientSecret, redirectUri); var tags = new InstaSharp.Endpoints.Tags.Unauthenticated(config); var result = tags.Recent(RemoveSpecialCharacters(searchtag.Replace(" ", String.Empty))); int i = 0; foreach (var gg in result.Data) { if (i == 4) { break; } list.Add(gg.Images.StandardResolution.Url + "~" + gg.Link.ToString()); //listz.Add(gg.Link.ToString()); i++; } return(new JavaScriptSerializer().Serialize(list)); //+ "\\" + new JavaScriptSerializer().Serialize(listz); }
public SubscriptionController(ISubscriptionRepository subscriptions, ILogger log, InstagramConfig config) { _log = log; _config = config; _subscriptionEndpoint = new Subscription(_config); _subscriptions = subscriptions; }
public RecentMediaController(ILogger log, InstagramConfig config, ISubscriptionRepository subscriptions) { _geoEndpoint = new Geographies(config); _tagEndpoint = new Tags(config); _config = config; _log = log; _subscriptions = subscriptions; }
public InstagramAPIManager() { config = new InstaSharp.InstagramConfig(apiUri, oAuthUri, clientId, clientSecret, redirectUri); List<Auth.Scope> scopes = new List<Auth.Scope>(); scopes.Add(Auth.Scope.basic); authInfo = GetInstagramAuth(oAuthUri, clientId, redirectUri, config, login, password); }
/// <summary> /// Get authentication link. /// </summary> /// <param name="config">Instagram configuration.</param> /// <param name="scopes">The scopes.</param> /// <param name="responseType">Type of the response.</param> /// <returns>The authentication url</returns> public static string AuthLink(InstagramConfig config, List <Scope> scopes, ResponseType responseType = ResponseType.Token) { var scopesForUri = BuildScopeForUri(scopes); return(BuildAuthUri(config.OAuthUri.TrimEnd('/') + "/authorize", config.ClientId, config.RedirectUri, responseType, scopesForUri)); }
public static void Initialize() { // Create the container as usual. var container = new Container(); //setup logger container.RegisterSingle<ILogger>(() => new LoggerConfiguration() .WriteTo.ColoredConsole() .WriteTo.Trace() .CreateLogger() ); //instagram config for InstaSharp container.RegisterSingle<InstagramConfig>(() => { var clientId = ConfigurationManager.AppSettings["clientId"]; var clientSecret = ConfigurationManager.AppSettings["clientSecret"]; var callbackUri = ConfigurationManager.AppSettings["callbackUri"]; var redirectUri = ConfigurationManager.AppSettings["redirectUri"]; var icfg = new InstagramConfig(clientId, clientSecret); icfg.CallbackUri = callbackUri; icfg.RedirectUri = redirectUri; return icfg; } ); // Azure storage account container.RegisterSingle(() => { var connectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; return CloudStorageAccount.Parse(connectionString); }); // Azure table client container.RegisterSingle(() => container.GetInstance<CloudStorageAccount>().CreateCloudTableClient()); //register our tablesets, in this case we only have one container.RegisterWebApiRequest<ITableSet<RealtimeSubscription>>(() => new TableSet<RealtimeSubscription>(container.GetInstance<CloudTableClient>()) ); //register repositories container.Register<ISubscriptionRepository, SubscriptionRepository>(Lifestyle.Singleton); // This is an extension method from the integration package. container.RegisterWebApiControllers(GlobalConfiguration.Configuration); container.Verify(); GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); }
public static void Initialize(HttpConfiguration config) { var clientId = WebConfigurationManager.AppSettings["MS_WebHookReceiverSecret_InstagramId"]; var clientSecret = WebConfigurationManager.AppSettings["MS_WebHookReceiverSecret_Instagram"]; var webHookHost = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME") ?? "localhost"; // Note: you can use the 'id' field of the callbackURI to manage multiple subscriptions with each their callback. var callbackUri = string.Format("https://{0}/api/webhooks/incoming/instagram", webHookHost); _config = new InstagramConfig(clientId, clientSecret, redirectUri: null, callbackUri: callbackUri); _tokens = new ConcurrentDictionary<string, OAuthResponse>(); }
public static InstagramConfig GetConfig(Uri requestUri) { var url = requestUri.Scheme + System.Uri.SchemeDelimiter + requestUri.Host + (requestUri.IsDefaultPort ? "" : ":" + requestUri.Port); var config = new InstagramConfig( ConfigurationManager.AppSettings["MS_WebHookReceiverSecret_InstagramId"], ConfigurationManager.AppSettings["MS_WebHookReceiverSecret_Instagram"], $"{url}/home/loginCallback"); return config; }
protected void Page_Load(object sender, EventArgs e) { var clientId = "769313f94a484b869c8e3ec8f0f44936"; var clientSecret = "9054ca26824d4a0cab5e09964434279d"; var redirectUri = "http://*****:*****@SG/default.aspx"; var config = new InstaSharp.InstagramConfig("https://api.instagram.com/v1", "https://api.instagram.com/oauth", clientId, clientSecret, redirectUri); var tags = new InstaSharp.Endpoints.Media.Unauthenticated(config); // tags.Uri = "https://api.instagram.com/v1/media/search"; var result = tags.Search(1.2777459830532, 103.8471120197759); //foreach (var gg in result.Data) //{ // string thumbnail = gg.Images.Thumbnail.Url; //} }
public void InstaSharpGetTest() { UserInfo info = new UserInfo { Id = 1952620338, Username = "******" }; OAuthResponse response = new OAuthResponse { AccessToken = ConfigurationManager.AppSettings["AccessToken"], User = info }; InstagramConfig config = new InstagramConfig(ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ClientSecret"]); Users users = new Users(config, response); UsersResponse userResponse = users.Search("yoventura", 1).Result; int userId = userResponse.Data[0].Id; MediasResponse medias = users.Recent(userId.ToString(CultureInfo.InvariantCulture), Int64.MaxValue.ToString(), Int64.MinValue.ToString(), int.MaxValue, null, null).Result; }
/// <summary> /// Get authentication link. /// </summary> /// <param name="config">Instagram configuration.</param> /// <param name="scopes">The scopes.</param> /// <param name="responseType">Type of the response.</param> /// <returns>The authentication url</returns> public static string AuthLink(InstagramConfig config, List<Scope> scopes, ResponseType responseType = ResponseType.Token) { var scopesForUri = BuildScopeForUri(scopes); return BuildAuthUri(config.OAuthUri.TrimEnd('/') + "/authorize", config.ClientId, config.RedirectUri, responseType, scopesForUri); }
public async Task ReadMedia(InstaConfig configData, int keywordIndex) { var clientId = configData.id; var clientSecret = configData.secret; InstagramConfig config = new InstagramConfig(clientId, clientSecret); OAuthResponse oauthResponse = new OAuthResponse(); oauthResponse.Access_Token = configData.token; oauthResponse.User = new User() { FullName = "Dave Brown", Username = "******" }; var tagEndpoint = new InstaSharp.Endpoints.Tags(config, oauthResponse); try { List<String> keywords = new List<string>() { "photoshoot", "fashion", "model", "modeling", "modelling", "models" }; string currentKeyword = keywords[keywordIndex]; SendToLoggerAndConsole("The keyword we're going to work through: " + currentKeyword + " For token: " + configData.token.ToString()); MediasResponse recentMedia; try { recentMedia = await tagEndpoint.Recent(currentKeyword); } catch (Exception ex) { SendToLoggerAndConsole("There was a problem getting recent media."); log.Error("Here's the exception", ex); SendToLoggerAndConsole("Bailing out of this key: " + configData.token.ToString()); return; } var likesEndpoint = new InstaSharp.Endpoints.Likes(config, oauthResponse); var commentsEndpoint = new InstaSharp.Endpoints.Comments(config, oauthResponse); SendToLoggerAndConsole("We have " + recentMedia.Data.Count.ToString() + " images to work through"); SendToLoggerAndConsole("Here's the amount of likes we have remaining: " + recentMedia.RateLimitRemaining.ToString() + " For token: " + configData.token.ToString()); bool rateLimitExceeded = recentMedia.RateLimitRemaining < 4971; int badResponseCount = 1; foreach (var image in recentMedia.Data) { if (!image.UserHasLiked.Value) { if (!rateLimitExceeded) { SendToLoggerAndConsole("About to start liking now picture id: " + image.Id); try { var likeResponse = await likesEndpoint.Post(image.Id); rateLimitExceeded = likeResponse.RateLimitRemaining < 4971; SendToLoggerAndConsole("Like response: " + likeResponse.Meta.Code.ToString() + " For token: " + configData.token.ToString()); SendToLoggerAndConsole("You have : " + likeResponse.RateLimitRemaining.ToString() + " remaining on token: " + configData.token.ToString()); SendToLoggerAndConsole("You are working on keyword: " + currentKeyword); SendToLoggerAndConsole("Currently on Index: " + configData.index.ToString()); if (likeResponse.Meta.Code != System.Net.HttpStatusCode.OK) { SendToLoggerAndConsole("Because the like response was: " + likeResponse.Meta.Code.ToString() + " For token: " + configData.token.ToString()); SendToLoggerAndConsole("We're going to wait: " + (30 * badResponseCount).ToString() + " minutes before we like another shot"); await Task.Delay(new TimeSpan(0, 30 * badResponseCount, 0)).ConfigureAwait(continueOnCapturedContext: false); badResponseCount++; } else { badResponseCount = 1; SendToLoggerAndConsole("Just liked " + image.Id + " For token: " + configData.token.ToString()); await Task.Delay(new TimeSpan(0, 0, new Random(DateTime.Now.Millisecond).Next(200, 300))).ConfigureAwait(continueOnCapturedContext: false); } } catch { } } } } } catch { } }
public Auth(InstagramConfig config) { _config = config; }
/// <summary> /// Initializes a new instance of the <see cref="OAuth"/> class. /// </summary> /// <param name="config">The configuration.</param> public OAuth(InstagramConfig config) { this.config = config; }
public Media(InstagramConfig config, OAuthResponse oAuthResponse) { this.config = config; this.oAuthResponse = oAuthResponse; }
private static AuthInfo GetInstagramAuth(string oAuthUri, string clientId, string redirectUri, InstagramConfig config, string login, string password) { List<Auth.Scope> scopes = new List<Auth.Scope>(); scopes.Add(Auth.Scope.basic); var link = InstaSharp.Auth.AuthLink(oAuthUri, clientId, redirectUri, scopes); // User name in the specified node CookieAwareWebClient client = new CookieAwareWebClient(); // We went to the login page var result = client.DownloadData(link); var html = System.Text.Encoding.Default.GetString(result); // Take the token string csr = ""; string pattern = @"csrfmiddlewaretoken""\svalue=""(.+)"""; var r = new System.Text.RegularExpressions.Regex(pattern); var m = r.Match(html); csr = m.Groups[1].Value; // Login string loginLink = string.Format( "https://instagram.com/accounts/login/?next=/oauth/authorize/%3Fclient_id%3D{0}%26redirect_uri%3Dhttp%3A//www.pwr.wroc.pl%26response_type%3Dcode%26scope%3Dbasic", clientId); NameValueCollection parameters = new NameValueCollection(); parameters.Add("csrfmiddlewaretoken", csr); parameters.Add("username", login); parameters.Add("password", password); // You need to add the secret cookies received pre-login // Looking for something headers string agent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"; client.Headers["Referer"] = loginLink; client.Headers["Host"] = "instagram.com"; client.Headers["Content-Type"] = "application/x-www-form-urlencoded"; client.Headers["User-Agent"] = agent; client.Headers["Accept-Language"] = "pl-PL"; client.Headers["Accept"] = "text/html, application/xhtml+xml, */*"; client.Headers["Cache-Control"] = "no-cache"; // request var result2 = client.UploadValues(loginLink, "POST", parameters); // Fasting data received code // New link is not on the api, and on instagram string newPostLink = string.Format( "https://instagram.com/oauth/authorize/?client_id={0}&redirect_uri=http://www.pwr.wroc.pl&response_type=code&scope=basic", clientId); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newPostLink); request.AllowAutoRedirect = false; request.CookieContainer = client.CookieContainer; request.Referer = newPostLink; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.UserAgent = agent; string postData = string.Format("csrfmiddlewaretoken={0}&allow=Authorize", csr); request.ContentLength = postData.Length; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] loginDataBytes = encoding.GetBytes(postData); request.ContentLength = loginDataBytes.Length; Stream stream = request.GetRequestStream(); stream.Write(loginDataBytes, 0, loginDataBytes.Length); // send the request var response = request.GetResponse(); string location = response.Headers["Location"]; // Now take out the code and get the authentication pattern = @"www.pwr.wroc.pl\?code=(.+)"; r = new System.Text.RegularExpressions.Regex(pattern); m = r.Match(location); string code = m.Groups[1].Value; // Finally, we get an authentication token var auth = new InstaSharp.Auth(config); //.OAuth(InstaSharpConfig.config); // now we have to call back to instagram and include the code they gave us // along with our client secret var oauthResponse = auth.RequestToken(code); return oauthResponse; }
public static InstagramConfig GetConfig() { var cfg = new InstagramConfig(ApiUrl, OauthUrl, ClientId, ClientSecret, RedirectUrl); return cfg; }
public UpdateController(InstagramConfig config, ILogger log) { _config = config; _log = log; _notificationContext = GlobalHost.ConnectionManager.GetHubContext<NotifyHub>(); }
private bool ApiAuth() { ApiConfig = new InstagramConfig(ClientId, ClientKey); return ApiConfig != null; }
public OAuth(InstagramConfig config) { _config = config; }
public InstagramOAuth(InstagramConfig config) : base(config) { this.config = config; }