예제 #1
0
        /// <summary>
        /// 新浪微博发布一条新微博
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        /// <param name="message"></param>
        protected override void SocialSharePublish(string channelName, 
            string channelUrl, string message, SocialBase.SocialShareHandler callBack)
        {
            try
            {
                var social = SocialViewModel.Instance.DataInfos[SocialType.SINA];
                var netEngine = new SdkNetEngine();
                var cmdBase = new cmdUploadMessage
                {
                    status = message,
                    acessToken = social.AcessToken,
                    acessTokenSecret = social.RefreshToken
                };

                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE, cmdBase, (type, response) =>
                {
                    if (response.errCode == SdkErrCode.SUCCESS)
                    {
                        callBack(true, response.content);
                    }
                    else
                    {
                        callBack(false, response.content);
                    }
                });
            }
            catch(Exception ex)
            {
                callBack(false, ex.Message);
            }
        }
        private void weiboVisitFinish(Object sender, object obj)
        {
            string url  = (string)obj;
            string code = SdkUility.GetQueryParameter(url, "code");

            oauthClient.Authorize(code);

            //get at user list
            var         engine  = new SdkNetEngine();
            ISdkCmdBase cmdbase = null;

            cmdbase = new CmdAtUsers()
            {
                Keyword = "3"
            };
            var result = engine.RequestCmd(SdkRequestType.AT_USERS, cmdbase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                System.Console.WriteLine(result.content);
            }
            else
            {
                System.Console.WriteLine("the api didn't work correctly.");
            }
        }
예제 #3
0
        /// <summary>
        /// 新浪微博发布一条新微博
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="channelUrl"></param>
        /// <param name="message"></param>
        protected override void SocialSharePublish(string channelName,
                                                   string channelUrl, string message, SocialBase.SocialShareHandler callBack)
        {
            try
            {
                var social    = SocialViewModel.Instance.DataInfos[SocialType.SINA];
                var netEngine = new SdkNetEngine();
                var cmdBase   = new cmdUploadMessage
                {
                    status           = message,
                    acessToken       = social.AcessToken,
                    acessTokenSecret = social.RefreshToken
                };

                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE, cmdBase, (type, response) =>
                {
                    if (response.errCode == SdkErrCode.SUCCESS)
                    {
                        callBack(true, response.content);
                    }
                    else
                    {
                        callBack(false, response.content);
                    }
                });
            }
            catch (Exception ex)
            {
                callBack(false, ex.Message);
            }
        }
예제 #4
0
        private async Task <string> Postmsgpic(string content, BitmapImage contentPic)
        {
            var         engine  = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdPostMsgWithPic()
            {
                Status  = content,
                PicPath = SendPicPath
            };
            var result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE_PIC, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return(result.content);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #5
0
        private async Task <string> Timeline()
        {
            var         engine  = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdTimelines()
            {
                Count = "10",
                Page  = "1"
            };
            var result = await engine.RequestCmd(SdkRequestType.FRIENDS_TIMELINE, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return(result.content);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #6
0
        private async Task <string> PostMSgnopic(string contentStr)
        {
            var engine = new SdkNetEngine();

            ISdkCmdBase cmdBase = new CmdPostMessage()
            {
                Status = contentStr,
            };

            var result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return(result.content);
            }
            else
            {
                return(string.Empty);
            }
        }
        private async Task <string> Timeline()
        {
            var         engine  = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdUserTimeline()
            {
                UserId = "*****@*****.**",
                Count  = "2",
                Page   = "1"
            };
            var result = await engine.RequestCmd(SdkRequestType.USER_TIMELINE, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return(result.content);
            }
            else
            {
                return(string.Empty);
            }
        }
		private async Task<string> GetFriends()
		{
			var engine = new SdkNetEngine();
			ISdkCmdBase cmdBase = new CmdAtUsers()
			{
				Count = "10",
				Type = "0",
				Keyword = "a",
				Range = "2"
			};

			var result = await engine.RequestCmd(SdkRequestType.AT_USERS, cmdBase);
			if (result.errCode == SdkErrCode.SUCCESS)
			{
				return result.content;
			}
			else
			{
				return string.Empty;
			}
		}
예제 #9
0
        private async Task <string> AtUser()
        {
            var         engine  = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdAtUsers()
            {
                Count   = "10",
                Type    = "0",
                Keyword = "q",
                Range   = "2"
            };
            var result = await engine.RequestCmd(SdkRequestType.AT_USERS, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return(result.content);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #10
0
		private async Task<string> Timeline()
		{
			var engine = new SdkNetEngine();
			ISdkCmdBase cmdBase = new CmdTimelines()
			{
				Count = "10",
				Page = "1"
			};
			var result = await engine.RequestCmd(SdkRequestType.FRIENDS_TIMELINE, cmdBase);
			if (result.errCode == SdkErrCode.SUCCESS)
			{
				return result.content;

			}
			else
			{
				return string.Empty;
			}
		}
        private async Task<string> Timeline()
        {
            var engine = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdUserTimeline()
            {

                UserId="*****@*****.**",
                Count = "2",
                Page = "1"
            };
            var result = await engine.RequestCmd(SdkRequestType.USER_TIMELINE, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return result.content;
            }
            else
            {
                return string.Empty;   
            }
        }
예제 #12
0
        private async Task<string> Postmsgpic(string content, BitmapImage contentPic)
        {
            var engine = new SdkNetEngine();
            ISdkCmdBase cmdBase = new CmdPostMsgWithPic()
            {
                Status = content,
                PicPath = SendPicPath

            };
            var result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE_PIC, cmdBase);
            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return result.content;

            }
            else
            {
                return string.Empty;
            }
        }
예제 #13
0
        private async Task<string> PostMSgnopic(string contentStr)
        {
            var engine = new SdkNetEngine();

            ISdkCmdBase cmdBase = new CmdPostMessage()
            {
                Status = contentStr,
            };

            var result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE, cmdBase);

            if (result.errCode == SdkErrCode.SUCCESS)
            {
                return result.content;
            }
            else
            {
                return string.Empty;
            }
        }
예제 #14
0
        private void LoadSinaWeiboContent()
        {
            try
            {
                if (String.IsNullOrEmpty(PreferenceHelper.GetPreference("SinaWeibo_FollowerID")))
                {
                    MessageBox.Show("尚未设置新浪微博关注对象");
                    m_progressIndicatorHelper.PopTask();
                    return;
                }
                // Define a new net engine
                netEngine = new SdkNetEngine();

                // Define a new command base
                String strCount = PreferenceHelper.GetPreference("SinaWeibo_RecentCount");
                if (string.IsNullOrEmpty(strCount))
                {
                    strCount = "30";
                }
                String careID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
                cmdBase = new cdmUserTimeline
                {
                    acessToken = App.SinaWeibo_AccessToken,
                    userId = careID,
                    count = strCount
                };
                // Request server, the last parameter is set as default (".xml")
                netEngine.RequestCmd(SdkRequestType.USER_TIMELINE, cmdBase,
                    // Requeset callback
                    LoadSinaWeiboContentComplete);
            }
            catch (System.Exception ex)
            {
                UmengSDK.UmengAnalytics.reportError(ex);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("新浪微博加载过程中发生未知错误", "悲剧了>_<", MessageBoxButton.OK);
                    m_progressIndicatorHelper.PopTask();
                });
            }
        }
예제 #15
0
        private bool LoadSinaWeiboItems(LoadSinaWeiboStatusesCompleteDelegate complete)
        {
            String followerID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
            if (String.IsNullOrEmpty(followerID))
            {
                return false;
            }
            // Define a new net engine
            m_netEngine = new SdkNetEngine();

            // Define a new command base
            m_cmdBase = new cdmUserTimeline
            {
                acessToken = App.SinaWeibo_AccessToken,
                userId = followerID,
                count = "40"
            };
            // Request server, the last parameter is set as default (".xml")
            m_netEngine.RequestCmd(SdkRequestType.USER_TIMELINE, m_cmdBase,
                // Requeset callback
                delegate(SdkRequestType requestType, SdkResponse response)
                {
                    if (response.errCode == SdkErrCode.SUCCESS)
                    {
                        WStatuses statuses = null;
                        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(WStatuses));
                        statuses = ser.ReadObject(response.stream) as WStatuses;
                        complete(statuses);
                    }
                    else
                    {
                        return;
                    }
                });
            return true;
        }
예제 #16
0
        private async void ShareWeiBo()
        {

            Autho();
            await Task.Delay(1000);
            try
             {                
                SdkResponse result = null;
                var engine = new SdkNetEngine();
                //如果没有图片,则发送文字消息
                if (!string.IsNullOrWhiteSpace(info[1]))
                {
                    //微博分享图文消息,图片URI必须在本地,所以只能先下载
                    List<byte> arrayByte = new List<byte>();
                 
                    var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.ReplaceExisting);
                    //开始异步下载图片
                    HttpClient client = new HttpClient();
                    Stream stream = await client.GetStreamAsync(info[1]);
                    byte[] buffer = new byte[1000];
                    int read = 0;
                    while ((read = stream.Read(buffer, 0, 1000)) > 0)
                    {
                        arrayByte.AddRange(buffer);
                    }
                    await FileIO.WriteBytesAsync(photoStorageFile, arrayByte.ToArray());
                    var status = await CachedFileManager.CompleteUpdatesAsync(photoStorageFile);

                    client.Dispose();
                    stream.Dispose();

                    if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                    {
                        ISdkCmdBase cmdBase = new WeiboSDKForWinRT.CmdPostMsgWithPic()
                        {
                            Status =info[0],
                            PicPath = photoStorageFile.Path
                        };
                        result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE_PIC, cmdBase);
                        
                        await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                }
                else
                {
                    ISdkCmdBase cmdBase = new WeiboSDKForWinRT.CmdPostMessage()
                    {
                        Status = info[0]                    
                    };
                    result = await engine.RequestCmd(SdkRequestType.POST_MESSAGE, cmdBase);
                }

                if (result.errCode == SdkErrCode.SUCCESS)
                {
                    TB_Prompt.Text = "分享成功";
                    PromptStoryboard.Begin();
                }
                else if (result.errCode == SdkErrCode.NET_UNUSUAL)
                {
                    TB_Prompt.Text = "网络不可用";
                    PromptStoryboard.Begin();
                }
                else if (result.errCode == SdkErrCode.SERVER_ERR)
                {
                    TB_Prompt.Text = "服务器异常";
                    PromptStoryboard.Begin();
                }
                else if (result.errCode == SdkErrCode.TIMEOUT)
                {
                    TB_Prompt.Text = "发送超时";
                    PromptStoryboard.Begin();
                }
                else
                {
                    TB_Prompt.Text = "分享失败";
                    PromptStoryboard.Begin();
                }
            }
            catch(Exception ex)
            {
                TB_Prompt.Text = "分享失败";
                PromptStoryboard.Begin();
            }


        }
예제 #17
0
        private void SinaWeiboSend()
        {
            txtInput.IsReadOnly = true;
            netEngine = new SdkNetEngine();

            netEngine = new SdkNetEngine();

            // m_picURL为空说明发送纯文本
            if (String.IsNullOrEmpty(m_picURL))
            {
                cmdBase = new cmdUploadMessage
                {
                    status = txtInput.Text,
                    acessToken = App.SinaWeibo_AccessToken
                };
                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE, cmdBase, weiboRequestCompleted);
            }
            else
            {
                cmdBase = new cmdUploadPic
                {
                    messageText = txtInput.Text,
                    picPath = m_picURL,
                    acessToken = App.SinaWeibo_AccessToken
                };
                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE_PIC, cmdBase, weiboRequestCompleted);
            }
        }