public AuthCheckToken ( string token ) : |
||
token | string | The authentication token to check. |
return |
protected Auth CheckAuthenticationToken(IAuthenticationSettings authenticationSettings) { if (string.IsNullOrEmpty(authenticationSettings.FlickrAuthToken)) { throw new Exception("No Flickr AuthToken!"); } Flickr.CacheTimeout = new TimeSpan(1, 0, 0, 0, 0); var flickrService = new Flickr(authenticationSettings.FlickrApiKey, authenticationSettings.FlickrApiSecret, authenticationSettings.FlickrAuthToken); var authenticationToken = flickrService.AuthCheckToken(authenticationSettings.FlickrAuthToken); return authenticationToken; }
private void GetPhotoButton_Click(object sender, EventArgs e) { Flickr flickr = new Flickr(ApiKey.Text, SharedSecret.Text, AuthToken.Text); Auth auth = flickr.AuthCheckToken(AuthToken.Text); PhotoSearchOptions options = new PhotoSearchOptions(auth.User.UserId); options.SortOrder = PhotoSearchSortOrder.DatePostedDescending; options.PerPage = 1; PhotoCollection photos = flickr.PhotosSearch(options); Flickr.FlushCache(flickr.LastRequest); Photo photo = photos[0]; webBrowser1.Navigate(photo.SmallUrl); OldTitle.Text = photo.Title; PhotoId.Text = photo.PhotoId; }
public async Task<HttpResponseMessage> PostImage([ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey) { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } // Read the file string root = HttpContext.Current.Server.MapPath("~/App_Data"); var provider = new MultipartFormDataStreamProvider(root); if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } using (var db = new BGNewsDB()) { var user = db.Users.FirstOrDefault(x => x.SessionKey == sessionKey); if (user == null) { return Request.CreateResponse(HttpStatusCode.Unauthorized); } try { // Read the form data. await Request.Content.ReadAsMultipartAsync(provider); // This illustrates how to get the file names. foreach (MultipartFileData file in provider.FileData) { Trace.WriteLine(file.Headers.ContentDisposition.FileName); Trace.WriteLine("Server file path: " + file.LocalFileName); string fileName = file.LocalFileName; Flickr flickr = new Flickr("8429718a57e817718d524ea6366b5b42", "3504e68e5812b923", "72157635282605625-a5feb0f5a53c4467"); var result = flickr.UploadPicture(fileName); System.IO.File.Delete(file.LocalFileName); // Take the image urls from flickr Auth auth = flickr.AuthCheckToken("72157635282605625-a5feb0f5a53c4467"); PhotoSearchOptions options = new PhotoSearchOptions(auth.User.UserId); options.SortOrder = PhotoSearchSortOrder.DatePostedDescending; options.PerPage = 1; ICollection<Photo> photos = flickr.PhotosSearch(options); Flickr.FlushCache(flickr.LastRequest); Photo photo = photos.First(); user.ProfilePictureUrlMedium = photo.MediumUrl; user.ProfilePictureUrlThumbnail = photo.SquareThumbnailUrl; break; } return Request.CreateResponse(HttpStatusCode.Created); } catch (System.Exception e) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e); } } }
/// <summary> /// uses authtoken from config and tries to connect. if there is any error throw exception. /// </summary> public void Connect() { _flickrObj = CreateFlickr(); Auth authorization = _flickrObj.AuthCheckToken(_flickrObj.AuthToken); string userId = authorization.User.UserId; }
// Lecture de la configuration static void ReadConfig() { string config_file = "config.xml"; if (!System.IO.File.Exists(config_file)) { var newconf = new System.Xml.XmlTextWriter(config_file, null); newconf.WriteStartDocument(); newconf.WriteStartElement("config"); newconf.WriteElementString("last_update", "0"); newconf.WriteElementString("auth_token", ""); newconf.WriteEndElement(); newconf.WriteEndDocument(); newconf.Close(); } var conf = new System.Xml.XmlTextReader(config_file); string CurrentElement = ""; while (conf.Read()) { switch(conf.NodeType) { case System.Xml.XmlNodeType.Element: CurrentElement = conf.Name; break; case System.Xml.XmlNodeType.Text: if (CurrentElement == "last_update") LastUpdate = DateTime.Parse(conf.Value); if (CurrentElement == "auth_token") AuthToken = conf.Value; break; } } conf.Close(); // On vérifie que le token est encore valide if (AuthToken.Length > 0) { var flickr = new Flickr(Program.ApiKey, Program.SharedSecret); try { Auth auth = flickr.AuthCheckToken(AuthToken); Username = auth.User.UserName; } catch (FlickrApiException ex) { //MessageBox.Show(ex.Message, "Authentification requise", // MessageBoxButtons.OK, MessageBoxIcon.Exclamation); AuthToken = ""; } } }
static void Main(string[] args) { StringBuilder errorLog = new StringBuilder(); errorLog.AppendFormat("Starting Run at {0}\n", DateTime.Now.ToString()); string baseDir = ConfigurationSettings.AppSettings["LocalDir"].ToString(); Flickr flickr = new Flickr(ConfigurationSettings.AppSettings["APIKey"].ToString(), ConfigurationSettings.AppSettings["APISecret"].ToString()); flickr.AuthToken = ""; Auth auth = flickr.AuthCheckToken(""); PhotoSearchOptions searchOptions = new PhotoSearchOptions(); searchOptions.PrivacyFilter = PrivacyFilter.None; searchOptions.UserId = auth.User.UserId; searchOptions.PerPage = 500; PhotoCollection pics = new PhotoCollection(); WebClient wget = new WebClient(); searchOptions.Extras |= PhotoSearchExtras.DateTaken | PhotoSearchExtras.OriginalFormat | PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.Description | PhotoSearchExtras.Tags; PhotoCollection rev = flickr.PhotosSearch(searchOptions); while (rev.Pages >= searchOptions.Page) { foreach(Photo pic in rev){ //We have a picture. string year = pic.DateTaken.Year.ToString("0000"); string month = pic.DateTaken.Month.ToString("00"); string day = pic.DateTaken.Day.ToString("00"); // Does the directory Exist // No string directory = String.Format("{0}{1}\\{2}\\{3}\\", baseDir, year, month, day); try { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string fileName = string.Format("{0}.{1}", pic.PhotoId, pic.OriginalFormat); string finalDestination = String.Format("{0}{1}", directory, fileName); if (!File.Exists(finalDestination)) { wget.DownloadFile(pic.OriginalUrl, finalDestination); FileInfo fi = new FileInfo(finalDestination); if (fi.Length < 10000) { //This shoudl catch file unavailable throw new Exception("File size is too small"); } StreamWriter dataFile = new StreamWriter(String.Format("{0}{1}.xml", directory, fileName)); StringBuilder meta = new StringBuilder(); meta.AppendFormat("<xml>\n\t<file>{0}</file>\n\t<title>{1}</title>\n\t<description>{2}</description>\n\t<dateTaken>{3}</dateTaken>\n\t<tags>", fileName, pic.Title, pic.Description, pic.DateTaken.ToString()); foreach(String tag in pic.Tags){ meta.AppendFormat("\n\t\t<tag>{0}</tag>", tag); } meta.Append("\n\t</tags>\n</xml>"); dataFile.Write(meta.ToString()); dataFile.Close(); } } catch (System.Exception ex) { errorLog.AppendFormat("{0}:{1}:{2}\n", directory, pic.PhotoId, ex.Message); } } searchOptions.Page = rev.Page + 1; rev = flickr.PhotosSearch(searchOptions); } errorLog.AppendFormat("Finished Run at {0}\n", DateTime.Now.ToString()); StreamWriter file = new StreamWriter(ConfigurationSettings.AppSettings["LocalDir"].ToString() + "/errors.log"); file.Write(errorLog.ToString()); file.Close(); }
public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent) { DialogResult result; DoWorkEventHandler handler = null; FlickrNet.Auth validAuthToken = null; FlickrContext context = new FlickrContext(base.Options); token = context.FlickrAuthToken; // we have a token saved already and // need to verify it with Flickr if (!string.IsNullOrEmpty(token)) { using (VerifyAuth vauth = new VerifyAuth()) { if (handler == null) { handler = delegate(object sender, DoWorkEventArgs args) { FlickrNet.Flickr fp = FlickrPluginHelper.GetFlickrProxy(); validAuthToken = fp.AuthCheckToken(token); if (validAuthToken != null) { token = validAuthToken.Token; } }; } vauth.DoWork += handler; result = vauth.ShowDialog(dialogOwner); if (result != DialogResult.OK) { return(result); } } } /* we didn't get a valid auth token * it might have expired or is just invalid/revoked * prompt the user to re-auth * OR * we don't have a saved token and know * we need to get one first so show the auth process */ if (string.IsNullOrEmpty(token) || (validAuthToken == null)) { token = AuthManager.Authenticate(dialogOwner, context); } if (string.IsNullOrEmpty(token)) { return(DialogResult.Cancel); } using (InsertFlickrImageForm flickr = new InsertFlickrImageForm(new FlickrContext(base.Options))) { System.Windows.Forms.DialogResult formResult = flickr.ShowDialog(dialogOwner); context.FlickrUserId = flickr.FlickrUserId.Trim(); context.FlickrUserName = flickr.FlickrUserName.Trim(); context.FlickrAuthUserId = flickr.FlickrAuthUserId.Trim(); if (formResult == System.Windows.Forms.DialogResult.OK) { ImageSize imgsize = flickr.SelectedImageSize; foreach (FlickrNet.Photo photo in flickr.SelectedPhotos) { newContent += FlickrPluginHelper.GenerateFlickrHtml(photo, GetImageUrl(photo, imgsize), flickr.CssClass, flickr.BorderThickness, flickr.VerticalPadding, flickr.HorizontalPadding, flickr.Alignment, flickr.EnableHyperLink, flickr.FlickrUserId); } } return(formResult); } }