Skip to content

Instantly share code, notes, and snippets.

@mbmccormick
Created March 26, 2012 23:41
Show Gist options
  • Save mbmccormick/2210715 to your computer and use it in GitHub Desktop.
Save mbmccormick/2210715 to your computer and use it in GitHub Desktop.
Uploading an image to Winstagram
WebServiceClient client = null;
public static void Main(string[] args)
{
client = new WebServiceClient("YOUR_API_KEY");
// login with user's credentials
client.AuthenticateCompleted += new RequestCompletedEventHandler(client_AuthenticateCompleted);
client.Authenticate("YOUR_USERNAME", "YOUR_PASSWORD");
}
private static void client_AuthenticateCompleted(object sender, RequestCompletedEventArgs e)
{
// authentication succeeeded, store this password
string hashedPassword = client.HashPassword("YOUR_PASSWORD");
// upload the image
client.UploadPictureCompleted += new RequestCompletedEventHandler(client_UploadPictureCompleted);
client.UploadPicture(YOUR_IMAGE_STREAM);
}
private static void client_UploadPictureCompleted(object sender, RequestCompletedEventArgs e)
{
// extract response
PictureURL result = e.Data as PictureURL;
// create new picture
Picture data = new Picture();
data.Caption = "This is my caption.";
data.Latitude = 100.000;
data.Longitude = -100.000;
data.URL = result.URL;
// upload the picture object
client.CreatePictureCompleted += new RequestCompletedEventHandler(client_CreatePictureCompleted);
client.CreatePicture(data);
}
private static void client_CreatePictureCompleted(object sender, RequestCompletedEventArgs e)
{
// your picture was uploaded successfully!
}
@mbmccormick
Copy link
Author

Code is in place to throw an exception in the event that authentication, upload, or creation methods fail. These should be handled appropriately by the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment