public static async Task<bool> ChangeUserProfile(String name, String url, String description, String location, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } var param = new Dictionary<String, String>(); if (!string.IsNullOrEmpty(name)) param.Add("name", name); if (!string.IsNullOrEmpty(url)) param.Add("url", url); if (!string.IsNullOrEmpty(location)) param.Add("location", location); if (!string.IsNullOrEmpty(description)) param.Add("description", description); var theAuthClient = new HttpClient(); HttpContent header = new FormUrlEncodedContent(param); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.ACCOUNT_UPDATE) {Content = header}; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.IsSuccessStatusCode; } catch (Exception) { return false; } }
public static async Task<List<PostEntity>> GetMentions(bool? trim, long? sinceId, long? maxId, int? count, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } string url = EndPoints.MENTIONS_TIMELINE + "?"; //if (trim != null) url += "&trim_user="******"&since_id=" + sinceId; if (maxId != null) url += "&max_id=" + maxId; if (count != null) url += "&count=" + count; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return PostEntity.Parse(responseContent, userAccountEntity); } catch (Exception) { return null; } }
public static async Task<HttpStatusCode> CreateSpread(long id, bool? trim, UserAccountEntity userAccountEntity) { var param = new Dictionary<String, String>(); if (trim == true) param.Add("trim_user", trim.ToString()); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, (String.Format(EndPoints.SPREAD_CREATE, id))); string accessToken = userAccountEntity.GetAccessToken(); if (accessToken.Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); accessToken = userAccountEntity.GetAccessToken(); } HttpContent header = new FormUrlEncodedContent(param); request.Content = header; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.StatusCode; } catch (Exception) { return HttpStatusCode.BadRequest; } }
/// <summary> /// アクセストークンを更新します。 /// </summary> /// <param name="account">対象のアカウント</param> public static async Task<bool> RefreshAccessToken(UserAccountEntity account) { var dic = new Dictionary<String, String>(); dic["grant_type"] = "refresh_token"; dic["client_id"] = Constants.CONSUMER_KEY; dic["client_secret"] = Constants.CONSUMER_SECRET; dic["refresh_token"] = account.GetRefreshToken(); account.SetAccessToken("updating", null); account.SetRefreshTime(1000); var theAuthClient = new HttpClient(); HttpContent header = new FormUrlEncodedContent(dic); HttpResponseMessage response; try { response = await theAuthClient.PostAsync(EndPoints.OAUTH_TOKEN, header); } catch (WebException) { return false; } if (response.StatusCode != HttpStatusCode.OK) return false; string responseContent = await response.Content.ReadAsStringAsync(); JObject o = JObject.Parse(responseContent); account.SetAccessToken((String) o["access_token"], (String) o["refresh_token"]); account.SetRefreshTime(long.Parse((String) o["expires_in"])); CroudiaAuthEntity authEntity = CroudiaAuthEntity.Parse(responseContent); AppSettings["refreshToken"] = authEntity.RefreshToken; AppSettings["accessToken"] = authEntity.AccessToken; AppSettings.Save(); return true; }
public static async Task<List<UserEntity>> SearchUserList(string query, int? count, int? page, bool trim, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } var paramer = "?q=" + query; if (count.HasValue) { paramer += "&count=" + count.Value; } if (page.HasValue) { paramer += "&page=" + page.Value; } if (trim) { paramer += "&trim_user="******"Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return UserEntity.ParseUserList(responseContent, userAccountEntity); } catch (Exception) { return null; } }
public static async Task<bool> UpdateStatus(String status, long? inReply, bool? inQuote, bool? trim, UserAccountEntity userAccountEntity) { var param = new Dictionary<String, String> {{"status", status}}; if (inReply != null) param.Add("in_reply_to_status_id", inReply.ToString()); if (inQuote == true) param.Add("in_reply_with_quote", true.ToString()); if (trim == true) param.Add("trim_user", true.ToString()); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.STATUS_UPDATE); string accessToken = userAccountEntity.GetAccessToken(); if (accessToken.Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); accessToken = userAccountEntity.GetAccessToken(); } HttpContent header = new FormUrlEncodedContent(param); request.Content = header; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.IsSuccessStatusCode; } catch (Exception) { return false; } }
public static List<SecretMailEntity> Parse(String json, UserAccountEntity userAccountEntity) { var entity = new List<SecretMailEntity>(); JArray a = JArray.Parse(json); foreach (JToken jToken in a) { var o = (JObject) jToken; var message = new SecretMailEntity { CreatedAt = FixTime((String) o["created_at"]), Recipient = UserEntity.Parse(o["recipient"].ToString(), userAccountEntity), RecipientScreenName = (String) o["recipient_screen_name"], RecipientId = long.Parse((String) o["recipient_id"]), Sender = UserEntity.Parse(o["sender"].ToString(), userAccountEntity), SenderScreenName = (String) o["sender_screen_name"], SenderId = long.Parse((String) o["sender_id"]), MessageContent = (String) o["text"], ID = long.Parse((String) o["id"]), IdStr = (String) o["id_str"] }; message.CreatedDate = ToDate(message.CreatedAt); entity.Add(message); } return entity; }
public static async Task<bool> CreateMail(String text, long? userId, String screenName, UserAccountEntity userAccountEntity) { var param = new Dictionary<String, String> {{"text", text}, {"user_id", userId.ToString()}}; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.MESSAGE_NEW); string accessToken = userAccountEntity.GetAccessToken(); if (accessToken.Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); accessToken = userAccountEntity.GetAccessToken(); } HttpContent header = new FormUrlEncodedContent(param); request.Content = header; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.IsSuccessStatusCode; } catch (Exception) { return false; } }
private async void WebBrowser_Navigated(object sender, NavigationEventArgs e) { String uri = e.Uri.ToString(); if (uri.StartsWith("https://twitter.com/innerlogic?code")) { // Remove junk text added by facebook from url if (uri.EndsWith("#_=_")) uri = uri.Substring(0, uri.Length - 4); String queryString = e.Uri.Query; // Acquire the code from Query String IEnumerable<KeyValuePair<string, string>> pairs = queryString.ParseQueryString(); code = pairs.GetValue("code"); await Auth.RequestAccessToken(code); var userAccountEntity = new UserAccountEntity(); await Auth.VerifyAccount(userAccountEntity); App.userAccountEntity = userAccountEntity; // Back to MainPage var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; if (rootFrame != null) rootFrame.Navigate(new Uri("/MainTimelinePivot.xaml", UriKind.Relative)); } }
public static async Task<PostEntity> GetPost(bool? trim, bool? entities, long postId, UserAccountEntity userAccountEntity) { string url = string.Format(EndPoints.STATUS_SHOW, postId); if (trim != null) url += "&trim_user="******"&include_entities=" + entities; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); JObject post = JObject.Parse(responseContent); return PostEntity.ParsePost(post, userAccountEntity); }
public static async Task<SearchEntity> SearchStatusList(string query, long? MaxId, long? SinceId, int? count, bool trim, bool entities, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } string paramer = "?q=" + query; if (MaxId.HasValue) { paramer += "&max_id=" + MaxId.Value; } if (SinceId.HasValue) { paramer += "&since_id=" + SinceId.Value; } if (count.HasValue) { paramer += "&count=" + count.Value; } if (trim) { paramer += "&trim_user="******"&include_entities=" + true; } var param = new Dictionary<String, String>(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.SEARCH_VOICES + paramer); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); responseContent = "[" + responseContent + "]"; JArray a = JArray.Parse(responseContent); var b = (JObject)a[0]; if (b["statuses"] == null || b["search_metadata"] == null) return null; return SearchEntity.ParseStatuses(b["statuses"].ToString(), b["search_metadata"].ToString(), userAccountEntity); } catch (Exception) { return null; } }
public async Task<bool> BindToMentionsTimeline(UserAccountEntity userAccountEntry) { MentionsCollection = new InfiniteScrollingCollection { timeline = EndPoints.MENTIONS_TIMELINE, PostCollection = new ObservableCollection<PostEntity>(), userAccountEntity = userAccountEntry }; List<PostEntity> items = await TimelineManager.GetMentions(false, null, null, null, App.userAccountEntity); foreach (PostEntity item in items) { MentionsCollection.PostCollection.Add(item); } MentionsCollection.MaxStatusId = items.Last().StatusID; MentionsTimeLine.DataContext = MentionsCollection; MentionsTimeLine.ItemRealized += mentionsTimeLine_ItemRealized; return true; }
public static SecretMailEntity ParseMail(JObject o, UserAccountEntity userAccountEntity) { var message = new SecretMailEntity { CreatedAt = FixTime((String) o["created_at"]), Recipient = UserEntity.Parse(o["recipient"].ToString(), userAccountEntity), RecipientScreenName = (String) o["recipient_screen_name"], RecipientId = long.Parse((String) o["recipient_id"]), Sender = UserEntity.Parse(o["sender"].ToString(), userAccountEntity), SenderScreenName = (String) o["sender_screen_name"], SenderId = long.Parse((String) o["sender_id"]), MessageContent = (String) o["text"], ID = long.Parse((String) o["id"]), IdStr = (String) o["id_str"] }; message.CreatedDate = ToDate(message.CreatedAt); return message; }
public async Task<bool> BindToConversationTimeline(UserAccountEntity userAccountEntry) { ConversationCollection = new InfiniteScrollingCollection { timeline = EndPoints.PUBLIC_TIMELINE, PostCollection = new ObservableCollection<PostEntity>(), userAccountEntity = userAccountEntry }; List<PostEntity> items = await TimelineManager.GetConversation(App.ViewModel.SelectedPost, App.userAccountEntity); foreach (PostEntity item in items) { ConversationCollection.PostCollection.Add(item); } ConversationCollection.MaxStatusId = items.Last().StatusID; conversationTimeLine.DataContext = ConversationCollection; return true; }
public static List<UserEntity> ParseUserList(String json, UserAccountEntity userAccountEntity) { var userEntities = new List<UserEntity>(); JArray a = JArray.Parse(json); foreach (var jToken in a) { var o = (JObject) jToken; var user = new UserEntity { CoverImage = (String)o["cover_image_url_https"] ?? string.Empty, CreatedAt = (String) o["created_at"] == null ? 0 : FixTime((String) o["created_at"]), Description = (String) o["description"] ?? string.Empty, FavoritesCount = (String) o["favorites_count"] == null ? 0 : long.Parse((String) o["favorites_count"]), FollowersCount = (String) o["followers_count"] == null ? 0 : long.Parse((String) o["followers_count"]), FriendsCount = (String) o["friends_count"] == null ? 0 : long.Parse((String) o["friends_count"]), IsFollowing = (String) o["following"] != null && (!((String) o["following"]).Equals("underdevelopment") && Boolean.Parse((String) o["following"])), IsFollowRequest = (String) o["follow_request_sent"] != null && (!((String) o["follow_request_sent"]).Equals("underdevelopment") && Boolean.Parse((String) o["follow_request_sent"])), IsProtected = (String) o["protected"] != null && Boolean.Parse((String) o["protected"]), Location = (String) o["location"] ?? string.Empty, Name = Regex.Replace((String) o["name"], @"\t|\n|\r", ""), ProfileImage = (String) o["profile_image_url_https"], ScreenName = (String) o["screen_name"], StatusCount = (String) o["statuses_count"] == null ? 0 : long.Parse((String) o["statuses_count"]), URL = (String) o["url"] ?? string.Empty, UserID = long.Parse((String) o["id"]) }; user.IsNotFollowing = !user.IsFollowing; if (userAccountEntity != null && userAccountEntity.GetUserEntity() != null) { user.IsCurrentUser = user.UserID == userAccountEntity.GetUserEntity().UserID; user.IsNotCurrentUser = !user.IsCurrentUser; } userEntities.Add(user); } return userEntities; }
public static async Task<bool> ChangeUserProfileImage(String filePath, byte[] fileStream, UserAccountEntity userAccountEntity) { try { var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.ACCOUNT_UPDATE_IMAGE); var form = new MultipartFormDataContent(); if (userAccountEntity != null) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } } if (userAccountEntity != null) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); Stream stream = new MemoryStream(fileStream); var t = new StreamContent(stream); const string fileName = "testtesttesttest.jpg"; if (Path.GetExtension(fileName).Equals(".png")) { t.Headers.ContentType = new MediaTypeHeaderValue("image/png"); } else if (Path.GetExtension(fileName).Equals(".jpg") || Path.GetExtension(fileName).Equals(".jpeg")) { t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); } else { t.Headers.ContentType = new MediaTypeHeaderValue("image/gif"); } form.Add(t, @"""image""", fileName); request.Content = form; HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.IsSuccessStatusCode; } catch (WebException e) { return false; } }
public static async Task<List<MediaEntity>> GetAlbumList(int offSet, String screenName, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } var doc = new HtmlDocument(); var theAuthClient = new HttpClient(); var requestMsg = new HttpRequestMessage(new HttpMethod("GET"), "https://croudia.com/voices/album/" + screenName + "?offset=" + offSet); HttpResponseMessage response = await theAuthClient.SendAsync(requestMsg); string responseContent = await response.Content.ReadAsStringAsync(); responseContent = RemoveHtmlComments(responseContent); doc.LoadHtml(responseContent); var idList = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", "").Contains("contents")).Select(link => ConvertToLong(link.GetAttributeValue("id", ""))).ToList(); var imageList = doc.DocumentNode.Descendants("img").Where(node => node.GetAttributeValue("src", "").Contains("?large")).Select(link => ExtractId(link.GetAttributeValue("src", ""))).ToList(); var postList = doc.DocumentNode.Descendants("p").Select(link => link.InnerText).ToList(); return imageList.Select(t => "https://croudia.com/testimages/download/" + t).Select((url, i) => new MediaEntity(idList[i], url, postList[i], "", i)).ToList(); }
public async Task<bool> BindToPublicTimeline(UserAccountEntity userAccountEntry) { progressBar.Visibility = Visibility.Visible; PublicCollection = new InfiniteScrollingCollection { timeline = EndPoints.PUBLIC_TIMELINE, PostCollection = new ObservableCollection<PostEntity>(), userAccountEntity = userAccountEntry }; List<PostEntity> items = await TimelineManager.GetPublicTimeline(false, null, null, null, App.userAccountEntity); foreach (PostEntity item in items) { PublicCollection.PostCollection.Add(item); } PublicCollection.MaxStatusId = items.Last().StatusID; publicTimeLine.DataContext = PublicCollection; publicTimeLine.ItemRealized += publicTimeLine_ItemRealized; progressBar.Visibility = Visibility.Collapsed; return true; }
public static SearchEntity ParseStatuses(string statuses, string searchMetaData, UserAccountEntity userAccountEntity) { if (statuses == null) throw new ArgumentNullException("statuses"); JArray statusList = JArray.Parse(statuses); JObject searchMeta = JObject.Parse(searchMetaData); var searchEntity = new SearchEntity { PostList = statusList != null ? PostEntity.Parse(statusList.ToString(), userAccountEntity) : null, CompletedIn = searchMeta["completed_in"] != null ? (Decimal) searchMeta["completed_in"] : 0, MaxId = searchMeta["max_id"] != null ? long.Parse((String) searchMeta["max_id"]) : 0, MaxIdStr = searchMeta["max_id_str"] != null ? (String) searchMeta["max_id_str"] : string.Empty, SinceId = searchMeta["since_id"] != null ? long.Parse((String) searchMeta["since_id"]) : 0, SinceIdStr = searchMeta["since_id_str"] != null ? (String) searchMeta["since_id_str"] : string.Empty, Count = searchMeta["count"] != null ? (int) searchMeta["count"] : 0, NextResults = searchMeta["next_results"] != null ? (String) searchMeta["next_results"] : string.Empty, RefreshUrl = searchMeta["refresh_url"] != null ? (String) searchMeta["refresh_url"] : string.Empty, Query = searchMeta["query"] != null ? (String) searchMeta["query"] : string.Empty }; return searchEntity; }
public async Task<bool> BindToUserTimeline(UserAccountEntity userAccountEntity) { progressBar.Visibility = Visibility.Visible; searchUserCollection = new InfiniteScrollingUserCollection(); searchUserCollection.timeline = "Following"; //searchUserCollection.userId = App.ViewModel.SelectedUser.UserID; searchUserCollection.Offset = 0; searchUserCollection.userAccountEntity = userAccountEntity; searchUserCollection.UserCollection = new ObservableCollection<UserEntity>(); List<UserEntity> items = await SearchManager.SearchUserList(SearchUserBox.Text, null, null, false, userAccountEntity); foreach (UserEntity item in items) { searchUserCollection.UserCollection.Add(item); } searchUserCollection.Offset = 1; userList.DataContext = searchUserCollection; //userList.ItemRealized += followingTimeline_ItemRealized; progressBar.Visibility = Visibility.Collapsed; return true; }
public static async Task<TrendPlaceEntity> GetTrends(int woeId, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, string.Format(EndPoints.TrendsPlace, woeId)); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return TrendPlaceEntity.Parse(responseContent); } catch (Exception) { return null; } }
public static async Task<HttpStatusCode> DestroyStatus(long statusId, UserAccountEntity userAccountEntity) { var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, string.Format(EndPoints.STATUS_DESTROY, statusId)); string accessToken = userAccountEntity.GetAccessToken(); if (accessToken.Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); accessToken = userAccountEntity.GetAccessToken(); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.StatusCode; } catch (Exception) { return HttpStatusCode.BadRequest; } }
public async Task<bool> BindToSearchTimeline(UserAccountEntity userAccountEntity) { progressBar.Visibility = Visibility.Visible; searchVoiceCollection = new InfiniteScrollingCollection(); searchVoiceCollection.timeline = EndPoints.USER_TIMELINE; searchVoiceCollection.PostCollection = new ObservableCollection<PostEntity>(); searchVoiceCollection.userAccountEntity = userAccountEntity; //searchVoiceCollection.userName = App.ViewModel.SelectedUser.ScreenName; //searchVoiceCollection.UserId = App.ViewModel.SelectedUser.UserID; searchVoiceCollection.Query = SearchBox.Text; SearchEntity searchEntity = await SearchManager.SearchStatusList(SearchBox.Text, null, null, null, false, true, userAccountEntity); List<PostEntity> items = searchEntity.PostList; foreach (PostEntity item in items) { searchVoiceCollection.PostCollection.Add(item); } searchVoiceCollection.MaxStatusId = items.Last().StatusID; voiceList.DataContext = searchVoiceCollection; voiceList.ItemRealized += voiceList_ItemRealized; progressBar.Visibility = Visibility.Collapsed; return true; }
public static async Task<bool> CreateFriendship(long? id, UserAccountEntity userAccountEntity) { var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.FRIEND_CREATE + "?user_id=" + id); string accessToken = userAccountEntity.GetAccessToken(); if (accessToken.Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); accessToken = userAccountEntity.GetAccessToken(); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response; try { response = await theAuthClient.SendAsync(request); } catch (WebException) { return false; } return response.IsSuccessStatusCode; }
public async Task<bool> BindToUserTimeline(UserAccountEntity userAccountEntry) { UserCollection = new InfiniteScrollingCollection { timeline = EndPoints.USER_TIMELINE, PostCollection = new ObservableCollection<PostEntity>(), userAccountEntity = userAccountEntry, userName = _selectedUser.ScreenName, UserId = _selectedUser.UserID }; List<PostEntity> items = await TimelineManager.GetUserTimeline(_selectedUser.ScreenName, _selectedUser.UserID, null, null, null, null, App.userAccountEntity); foreach (PostEntity item in items) { UserCollection.PostCollection.Add(item); } UserCollection.MaxStatusId = items.Last().StatusID; userTimeLine.DataContext = UserCollection; userTimeLine.ItemRealized += userTimeLine_ItemRealized; return true; }
public static async Task<UserEntity> ShowUser(String screenname, long? userId, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } var paramer = string.Empty; if (screenname != null) { paramer += "?screen_name=" + screenname; } else if (userId != null) { paramer += "?user_id=" + userId; } else { return null; } var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.USERS_SHOW + paramer); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return UserEntity.Parse(responseContent, userAccountEntity); } catch (Exception) { return null; } }
public static async Task<List<UserEntity>> LookupFollowerUsers(int cursor, long? userId, UserAccountEntity userAccountEntity) { if (userAccountEntity.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(userAccountEntity); } string paramer = "?cursor=" + cursor + "&user_id=" + userId; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.FOLLOWERS_LIST + paramer); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); try { HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); responseContent = "[" + responseContent + "]"; JArray a = JArray.Parse(responseContent); var b = (JObject)a[0]; return UserEntity.ParseUserList(b["users"].ToString(), userAccountEntity); } catch (Exception) { return null; } }
public static async Task<bool> UpdateStatusWithMedia(String status, String path, byte[] fileStream, long? inReply, bool? isQuote, bool? trim, UserAccountEntity account) { try { Debug.WriteLine(EndPoints.STATUS_UPDATE_WITH_MEDIA); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.STATUS_UPDATE_WITH_MEDIA); var form = new MultipartFormDataContent(); if (account != null) { if (account.GetAccessToken().Equals("refresh")) { await Auth.RefreshAccessToken(account); } } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", account.GetAccessToken()); form.Add(new StringContent(status), @"""status"""); Stream stream = new MemoryStream(fileStream); var t = new StreamContent(stream); const string fileName = "test.jpg"; var extension = Path.GetExtension(path); if (extension != null && extension.Equals(".png")) { t.Headers.ContentType = new MediaTypeHeaderValue("image/png"); } else { var s = Path.GetExtension(path); if (s != null && (s.Equals(".jpg") || s.Equals(".jpeg"))) { t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); } else { t.Headers.ContentType = new MediaTypeHeaderValue("image/gif"); } } t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); form.Add(t, @"""media""", fileName); request.Content = form; HttpResponseMessage response = await theAuthClient.SendAsync(request); return response.IsSuccessStatusCode; } catch (WebException e) { Debug.WriteLine(((HttpWebResponse) e.Response).StatusDescription); Debug.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd()); return false; } }
public async Task<bool> BindToUserFollowingGallery(UserAccountEntity userAccountEntity) { UserFollowingCollection = new InfiniteScrollingUserCollection { timeline = "Following", userId = _selectedUser.UserID, Offset = -1, userAccountEntity = userAccountEntity, UserCollection = new ObservableCollection<UserEntity>() }; List<UserEntity> items = await UserManager.LookupFollowingUsers(0, _selectedUser.UserID, userAccountEntity); foreach (UserEntity item in items) { UserFollowingCollection.UserCollection.Add(item); } UserFollowingCollection.Offset = 0; followingList.DataContext = UserFollowingCollection; followingList.ItemRealized += followingTimeline_ItemRealized; return true; }
public async Task<bool> BindPictureGallery(UserAccountEntity userAccountEntity) { PictureCollection = new InfiniteScrollingHtmlParseImageCollection { timeline = "Pictures", userAccountEntity = userAccountEntity, Offset = 0, userName = _selectedUser.ScreenName, MediaCollection = new ObservableCollection<MediaEntity>() }; List<MediaEntity> items = await AlbumManager.GetAlbumList(0, _selectedUser.ScreenName, userAccountEntity); foreach (MediaEntity item in items) { PictureCollection.MediaCollection.Add(item); } PictureCollection.Offset = 20; albumGallery.DataContext = PictureCollection; albumGallery.ItemRealized += albumGallery_ItemRealized; return true; }