public string MakeYahooPostSample() { var client = new RestClient { Authority = "http://api.search.yahoo.com/ContentAnalysisService", VersionPath = "V1" }; var request = new RestRequest { Path = "termExtraction", Method = WebMethod.Post }; var appId = "YahooDemo"; var context = "Italian sculptors and painters of the renaissance favored the Virgin Mary for inspiration"; var query = "madonna"; request.AddField("appid", appId); request.AddField("context", context); request.AddField("query", query); var response = client.Request(request); return response.Content; }
private void ApplicationBarIconButton_Click(object sender, EventArgs e) { if (WatermarkTB.Text == emptystr) { MessageBox.Show("Please input your mind :)", "Sorry", MessageBoxButton.OK); return; } RestClient client2 = new RestClient { Authority = "https://graph.facebook.com/", }; RestRequest request2 = new RestRequest { Path = id+"/comments?message=" + WatermarkTB.Text }; request2.AddField("access_token", (string)settings["facebook_token"]); var callback = new RestCallback( (restRequest, restResponse, userState) => { Dispatcher.BeginInvoke(delegate() { ScrollViewer.Height = 680; ScrollViewer.UpdateLayout(); ScrollViewer.ScrollToVerticalOffset(double.MaxValue); WatermarkTB.Text = emptystr; keyboard.txt = ""; keyboard.Init(); KeyboardPanel.Visibility = Visibility.Collapsed; comment_list.Children.Clear(); loadpg.Visibility = Visibility.Visible; SolidColorBrush Brush1 = new SolidColorBrush(); Brush1.Color = Colors.Gray; WatermarkTB.Foreground = Brush1; }); string url = String.Format("https://graph.facebook.com/{0}?access_token={1}", id, (string)settings["facebook_token"]); WebClient wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_openHandler); wc.DownloadStringAsync(new Uri(url), UriKind.Absolute); } ); client2.BeginRequest(request2, callback); }
public void LoginAsync(string email, string password, Action<LoginInfo> report) { var request = new RestRequest { Path = "token", Method = WebMethod.Post, }; request.AddField("email", email); request.AddField("password", password); request.AddField("oauth_signature_method", "HMAC-SHA1"); request.AddField("oauth_consumer_key", DropBoxInfo.KEY); ClearAuthenticator(); _client.BeginRequest<LoginInfo>(request, (req, res, state) => { if (res.StatusCode != HttpStatusCode.OK) { report(null); return; } var data = res.ContentEntity; InitAuthenticator(data.Token, data.Secret); report(data); }); }
private void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { img_bool = true; var client = new RestClient { Authority = "http://api.twipl.net/", VersionPath = "1", }; var request = new RestRequest { Path = "upload.json" // can be upload.xml or whatever, but you have to parse it accordingly }; request.AddFile("media1", "img.jpg", e.ChosenPhoto); request.AddField("key", "b76ecda29f7c47e0bfefd0b458e91fb5"); request.AddField("oauth_token", (string)settings["twitter_token"]); request.AddField("oauth_secret", (string)settings["twitter_tokensecret"]); request.AddField("message", ""); client.BeginRequest(request, new RestCallback(Callback)); } }
//void fb_PostCompleted(object sender, FacebookApiEventArgs e) //{ // if (e.Error != null) // { // Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message)); // return; // } // else // { // Dispatcher.BeginInvoke(() => // { // progbar1.IsIndeterminate = false; // progbar1.Visibility = Visibility.Collapsed; // MessageBox.Show("Successfully shared on Facebook"); // //if (NavigationService.CanGoBack) // // NavigationService.GoBack(); // }); // } //} public void ShareOnTwitter() { OAuthCredentials credentials = new OAuthCredentials(); credentials.Type = OAuthType.ProtectedResource; credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1; credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; credentials.ConsumerKey = TwitterSettings.ConsumerKey; credentials.ConsumerSecret = TwitterSettings.ConsumerKeySecret; credentials.Token = tokenx; credentials.TokenSecret = tokensecx; credentials.Version = "1.0"; //credentials.ClientUsername = ""; //credentials.CallbackUrl = "www.google.com"; //var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret); //service.AuthenticateWith(tokenx, tokensecx); //var resized = img.Resize(img.PixelWidth / 4, img.PixelHeight / 4, WriteableBitmapExtensions.Interpolation.Bilinear); //var fileStream = new MemoryStream(); //resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100); //fileStream.Seek(0, SeekOrigin.Begin); //SendTweetWithMediaOptions msgMedia = new SendTweetWithMediaOptions(); //msgMedia.Status = photo_text.Text; //Dictionary<string, Stream> imageDict = new Dictionary<string, Stream> { { fileName, fileStream } }; ////imageDict.Add(imagePath, imageStream); //msgMedia.Images = imageDict; ////status = service.SendTweetWithMedia(new SendTweetWithMediaOptions() { Status = readerMsg.Message, Images = imageDict }); //service.SendTweetWithMedia(msgMedia, tweetResponse); //other method RestClient _client = new RestClient { Authority = "https://api.twitter.com", HasElevatedPermissions = true, }; var twitterRequest = new RestRequest { Credentials = credentials, Path = "/1.1/statuses/update_with_media.json", Method = WebMethod.Post }; //twitterRequest.AddHeader("content-type", "application/x-www-form-urlencoded"); //twitterRequest.AddHeader("content-type", "multipart/form-data"); //twitterRequest.AddField("consumer_token", TwitterSettings.ConsumerKey); //twitterRequest.AddField("consumer_secret", TwitterSettings.ConsumerKeySecret); //twitterRequest.AddField("oauth_token", tokenx); //twitterRequest.AddField("oauth_secret", tokensecx); var resized = img.Resize(img.PixelWidth / 4, img.PixelHeight / 4, WriteableBitmapExtensions.Interpolation.Bilinear); var fileStream = new MemoryStream(); resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100); fileStream.Seek(0, SeekOrigin.Begin); //twitterRequest.AddParameter("status", photo_text.Text); twitterRequest.AddField("status", photo_text.Text); twitterRequest.AddFile("media[]", "test", fileStream, "image/jpeg"); _client.BeginRequest(twitterRequest, NewTweetCompleted); // another method // var resized = img.Resize(img.PixelWidth / 4, img.PixelHeight / 4, WriteableBitmapExtensions.Interpolation.Bilinear); // var fileStream = new MemoryStream(); // resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100); // fileStream.Seek(0, SeekOrigin.Begin); // string fileUploadUrl = "http://api.twitter.com/1.1/statuses/update_with_media.json"; // HttpClientHandler handler = new HttpClientHandler(); //// handler.Credentials = new NetworkCredential("username", "password"); // handler.Credentials = new NetworkCredential(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret); // HttpClient client = new HttpClient(handler); // fileStream.Position = 0; // MultipartFormDataContent content = new MultipartFormDataContent(); // content.Add(new StreamContent(fileStream), "media[]", fileName); // await client.PostAsync(fileUploadUrl, content) // .ContinueWith((postTask) => // { // postTask.Result.EnsureSuccessStatusCode(); // }); }
private void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { img_bool = true; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists("img.jpg")) { myIsolatedStorage.DeleteFile("img.jpg"); } IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("img.jpg"); Uri uri = new Uri("img.jpg", UriKind.Relative); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(e.ChosenPhoto); WriteableBitmap wb = new WriteableBitmap(bitmap); System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); fileStream.Close(); photo.Content = "Remove a picture"; if (twitter_chk.IsChecked == true) { share_pg.Visibility = Visibility.Visible; share.Visibility = Visibility.Collapsed; var client = new RestClient { Authority = "http://api.twipl.net/", VersionPath = "1", }; var request = new RestRequest { Path = "upload.json" // can be upload.xml or whatever, but you have to parse it accordingly }; IsolatedStorageFileStream fileStream2 = myIsolatedStorage.OpenFile("img.jpg", FileMode.Open, FileAccess.Read); request.AddFile("media1", "img.jpg", fileStream2); request.AddField("key", "b76ecda29f7c47e0bfefd0b458e91fb5"); request.AddField("oauth_token", (string)settings["twitter_token"]); request.AddField("oauth_secret", (string)settings["twitter_tokensecret"]); request.AddField("message", ""); client.BeginRequest(request, new RestCallback(Callback)); } } } }
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e) { RestClient client2 = new RestClient { Authority = "https://graph.facebook.com/", }; RestRequest request2 = new RestRequest { Path = id + "/likes", }; request2.AddField("access_token", (string)settings["facebook_token"]); var callback = new RestCallback( (restRequest, restResponse, userState) => { Dispatcher.BeginInvoke(delegate() { if (like_cnt > 0) hour.Text += " 하고 나도 좋아요"; else hour.Text += "내가 좋아한 글"; }); } ); client2.BeginRequest(request2, callback); }
public static void CallDailyBurnApiPost(string apiExtensionPath, RestCallback callback, Dictionary<string, string> parameters) { string accessToken = HelperMethods.GetKeyValue("accessToken"); string accessTokenSecret = HelperMethods.GetKeyValue("accessTokenSecret"); var credentials = new OAuthCredentials { Type = OAuthType.ProtectedResource, SignatureMethod = OAuthSignatureMethod.HmacSha1, ParameterHandling = OAuthParameterHandling.UrlOrPostParameters, ConsumerKey = DailyBurnSettings.consumerKey, ConsumerSecret = DailyBurnSettings.consumerKeySecret, Token = accessToken, TokenSecret = accessTokenSecret, Version = "1.0" }; var restClient = new RestClient { Authority = DailyBurnSettings.AuthorityUri, HasElevatedPermissions = true, Credentials = credentials, Method = WebMethod.Post }; var restRequest = new RestRequest { Path = apiExtensionPath, Method = WebMethod.Post }; if (parameters != null) { foreach (KeyValuePair<string, string> param in parameters) { restRequest.AddField(param.Key, param.Value); } } restClient.BeginRequest(restRequest, new RestCallback(callback)); }