Created
March 26, 2012 23:41
-
-
Save mbmccormick/2210715 to your computer and use it in GitHub Desktop.
Uploading an image to Winstagram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.