private void SinaWeiboSend() { String statusID = m_itemViewModel.ID; if (String.IsNullOrEmpty(statusID)) return; String commentText = StatusMessageBox.Text; netEngine = new SdkNetEngine(); // Define a new command base cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Post; request.Path = "comments/create.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("id", statusID); request.AddParameter("comment", commentText); request.AddParameter("comment_ori", "0"); netEngine.SendRequest(request, cmdBase, (SdkResponse response) => { if (response.errCode == SdkErrCode.SUCCESS) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("发送成功!"); // go back to CommentView. // CommentView should refresh itself to show the newly added comment NavigationService.GoBack(); } ); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("发送失败!"); // go back to CommentView. // CommentView should refresh itself to show the newly added comment NavigationService.GoBack(); }); } }); }
public void LoadSinaWeiboCommentByStatusID(String id, LoadSinaWeiboCommentsCompleteDelegate dele) { String MyID = PreferenceHelper.GetPreference("SinaWeibo_ID"); if (string.IsNullOrEmpty(MyID)) return; // Define a new net engine m_netEngine = new SdkNetEngine(); // Define a new command base m_cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "comments/show.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("id", id); //request.CacheOptions.Mode = Hammock.Caching.CacheMode.AbsoluteExpiration; ++App.Test3; System.Diagnostics.Debug.WriteLine("Test3: " + App.Test3); m_netEngine.SendRequest(request, m_cmdBase, (SdkResponse response) => { ++App.Test2; System.Diagnostics.Debug.WriteLine("Test2: " + App.Test2); if (response.errCode == SdkErrCode.SUCCESS) { Comments comments; try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Comments)); comments = ser.ReadObject(response.stream) as Comments; dele(comments); } catch (Exception) { dele(null); } } else { dele(null); } }); }
private void GetFriendList(int cursor) { m_progressIndicatorHelper.PushTask(); String myID = PreferenceHelper.GetPreference("SinaWeibo_ID"); if (string.IsNullOrEmpty(myID)) return; // Define a new net engine netEngine = new SdkNetEngine(); // Define a new command base cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "friendships/friends.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("uid", myID); if (cursor != -1) { request.AddParameter("cursor", cursor.ToString()); } // use my uid to get the friends list. netEngine.SendRequest(request, cmdBase, (SdkResponse response) => { if (response.errCode == SdkErrCode.SUCCESS) { Friends friends; try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Friends)); friends = ser.ReadObject(response.stream) as Friends; m_nPrevois = int.Parse(friends.previous_cursor); if (m_nCurrentIndex > m_listPrevios.Count - 1) { m_listPrevios.Add(m_nPrevois); } else { m_listPrevios[m_nCurrentIndex] = m_nPrevois; } m_nNext = int.Parse(friends.next_cursor); m_nTotalNumber = int.Parse(friends.total_number); Deployment.Current.Dispatcher.BeginInvoke(() => { m_progressIndicatorHelper.PopTask(); Friends.Clear(); foreach (User friend in friends.users) { //App.ViewModel.Friends.Add(friend); Friends.Add(friend); } ScrollViewer v = VisualTreeHelper.GetChild(this.ResultListBox, 0) as ScrollViewer; v.ScrollToVerticalOffset(0); } ); } catch (Exception) { m_progressIndicatorHelper.PopTask(); throw; } } else { m_progressIndicatorHelper.PopTask(); } }); }
// 得到关注用户信息 private void refreshFollowerSinaAccountInfo() { // Define a new net engine SdkNetEngine netEngine = new SdkNetEngine(); // Define a new command base SdkCmdBase cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "/users/show.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("uid", PreferenceHelper.GetPreference("SinaWeibo_FollowerID")); netEngine.SendRequest(request, cmdBase, (SdkResponse e1) => { if (e1.errCode == SdkErrCode.SUCCESS) { User user = null; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User)); user = ser.ReadObject(e1.stream) as User; String nickName = user.screen_name; PreferenceHelper.SetPreference("SinaWeibo_FollowerNickName", nickName); Deployment.Current.Dispatcher.BeginInvoke(() => { NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative)); }); } else { PreferenceHelper.RemovePreference("SinaWeibo_FollowerNickName"); Deployment.Current.Dispatcher.BeginInvoke(() => { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("此人不存在"); }); NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative)); }); } }); }
private void GetFriendListIterator(int cursor, FetchAllFriendsCallback callback) { m_progressIndicatorHelper.PushTask(); String myID = PreferenceHelper.GetPreference("SinaWeibo_ID"); if (string.IsNullOrEmpty(myID)) { m_progressIndicatorHelper.PopTask(); return; } // Define a new net engine netEngine = new SdkNetEngine(); // Define a new command base cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "friendships/friends.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("uid", myID); // curosr = -1 说明是第一次进来 if (cursor != -1) { request.AddParameter("cursor", cursor.ToString()); } else { AllFriends.Clear(); } // use my uid to get the friends list. netEngine.SendRequest(request, cmdBase, (SdkResponse response) => { if (response.errCode == SdkErrCode.SUCCESS) { Friends friends; try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Friends)); friends = ser.ReadObject(response.stream) as Friends; int next = int.Parse(friends.next_cursor); foreach (User friend in friends.users) { AllFriends.Add(friend); } // 如果还没有遍历完,则继续遍历 if (next != 0) { GetFriendListIterator(next, callback); } // 遍历完后执行后续回调(其实就是从得到的名单中搜索,刷新UI) else { callback(); } m_progressIndicatorHelper.PopTask(); } catch (Exception) { m_progressIndicatorHelper.PopTask(); throw; } } else { m_progressIndicatorHelper.PopTask(); } }); }
// 得到当前用户信息 private void refreshMySinaAccountInfo() { // Define a new net engine SdkNetEngine netEngine = new SdkNetEngine(); // Define a new command base SdkCmdBase cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "/users/show.json"; String myID = PreferenceHelper.GetPreference("SinaWeibo_ID"); request.AddParameter("access_token", App.SinaWeibo_AccessToken); request.AddParameter("uid", myID); netEngine.SendRequest(request, cmdBase, (SdkResponse e1) => { if (e1.errCode == SdkErrCode.SUCCESS) { User user = null; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User)); user = ser.ReadObject(e1.stream) as User; // TODO NULL detect PreferenceHelper.SetPreference("SinaWeibo_NickName", user.screen_name); PreferenceHelper.SetPreference("SinaWeibo_Avatar", user.profile_image_url); // 设置显示当前用户昵称的UI Deployment.Current.Dispatcher.BeginInvoke(() => { NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative)); }); } }); }
// 得到当前用户ID4 // 新浪微博必须要先得到当前用户ID,再根据此ID拿到当前用户信息 private void refreshMySinaAccountID() { // Define a new net engine SdkNetEngine netEngine = new SdkNetEngine(); // Define a new command base SdkCmdBase cmdBase = new SdkCmdBase { acessToken = App.SinaWeibo_AccessToken, }; RestRequest request = new RestRequest(); request.Method = WebMethod.Get; request.Path = "/account/get_uid.json"; request.AddParameter("access_token", App.SinaWeibo_AccessToken); netEngine.SendRequest(request, cmdBase, (SdkResponse e1) => { if (e1.errCode == SdkErrCode.SUCCESS) { try { JSONObject json = JSONConvert.DeserializeObject(e1.content); string uid = json["uid"] as string; PreferenceHelper.SetPreference("SinaWeibo_ID", uid); refreshMySinaAccountInfo(); } catch (Exception e) { Debug.WriteLine(e.ToString()); int a = 1; } } else { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBoxResult result = MessageBox.Show("新浪微博用户尚未登陆,或登陆已过期", "提示", MessageBoxButton.OK); if (result == MessageBoxResult.OK) { // WeiboLogin(null, null); } }); } }); }