Exemplo n.º 1
0
        /// <summary>
        /// 提交评论
        /// </summary>
        /// <param name="task"></param>
        public void PostComment(Beauty.App.BeautyService.WebTask task)
        {
            Beauty.App.BeautyService.WebLike like = client.GetLike(task.Taskid.ToString());
            if (like != null)
            {
                Beauty.App.BeautyService.WebBady bady = client.GetBady(like.Bady.ID.ToString());
                if (!string.IsNullOrEmpty(bady.Twitterid))
                {
                    string postdata = "stid=" + bady.Twitterid + "&type=4&tContent=" + task.Comment;

                    string html = HttpHelper.GetHtml("http://www.meilishuo.com/aw/twitter/create", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", postdata, true, user.Cookie, null, Encoding.UTF8, null, true);
                    try
                    {
                        JavaScriptSerializer serializer   = new JavaScriptSerializer();
                        PostShareResult      resultobject = serializer.Deserialize <PostShareResult>(html);
                        if (resultobject.code.HasValue && resultobject.code.Value == 0)
                        {
                            //client.CompleteShareTask(task.ID.ToString(), task.Taskid.ToString(), bady.ID.ToString(), obj.data.gInfo.goodsID.ToString(), resultobject.data.twitter_id.ToString(), resultobject.data.group_id.ToString());
                            client.BeginCompletelikeTask(task.ID.ToString(), like.ID.ToString(), null, null);
                            writelog("完成评论任务");
                        }
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = "An application error occurred. Please contact the adminstrator " +
                                          "with the following information:/n/n";
                        errorMsg += ex.Message + "/n/nStack Trace:/n" + ex.StackTrace + "//" + ex.Source;
                        client.BeginLog(errorMsg, null, null);
                    }
                }
            }
        }
    private bool PostLinkedIn()
    {
        string requestCode = Session[LinkedInCodeSessionKey].ToString();

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            //Session[TitleKey] = txtTitle.Text.Trim();

            var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
            var api    = new LinkedInApi(config);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress | AuthorizationScope.WriteShare | AuthorizationScope.ReadWriteCompanyPage;
            var state = Guid.NewGuid().ToString();
            var url   = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);

            Response.Redirect(url.AbsoluteUri, false);
        }
        else
        {
            int linkedInCompanyID = int.Parse(LinkedInCompanyID);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            try
            {
                string message = txtFeedContent.Text.Trim();

                var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
                // get the APIs client
                var api = new LinkedInApi(config);
                AuthorizationAccessToken userToken = api.OAuth2.GetAccessToken(requestCode, redirectUrl);

                if (userToken != null)
                {
                    string   acessToken           = userToken.AccessToken;
                    DateTime authorizationDateUTC = userToken.AuthorizationDateUtc;
                    int?     expiresIn            = userToken.ExpiresIn;

                    AccessTokenController accessTokenController = new AccessTokenController();
                    int addUpdateResult = accessTokenController.AddLinkedInAccessToken(acessToken, authorizationDateUTC, expiresIn);
                }

                UserAuthorization user = new UserAuthorization(userToken.AccessToken);

                PostShareResult postShareResult = api.Companies.Share(
                    user,
                    linkedInCompanyID, new PostShare()
                {
                    Visibility = new Visibility()
                    {
                        Code = "anyone"
                    },
                    Comment = message
                });

                string resultID = hdnSelectedMessageID.Value;
                SocialFeedController feedController = new SocialFeedController();
                UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(postShareResult.Location, postShareResult.UpdateKey, postShareResult.UpdateUrl, message, resultID);

                int output = feedController.SaveUserChoice(userChoiceInfo);

                if (output == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }

        return(false);
    }
Exemplo n.º 3
0
 public static LinkedInApiPaginatedResult <LikeElement> GetLikesForShare(this LinkedInApi api, PostShareResult share, int count = 500, int start = 0)
 => GetLikesForActivity(api, share.Activity, count, start);
Exemplo n.º 4
0
        /// <summary>
        /// 提交收录
        /// </summary>
        /// <param name="task"></param>
        public void PostRecord(Beauty.App.BeautyService.WebTask task)
        {
            try
            {
                Beauty.App.BeautyService.WebLike like = client.GetLike(task.Taskid.ToString());
                if (like != null)
                {
                    Beauty.App.BeautyService.WebBady  bady  = client.GetBady(like.Bady.ID.ToString());
                    Beauty.App.BeautyService.WebShare share = client.GetShareByBady(bady.ID.ToString());
                    if (share != null)
                    {
                        string type = task.Type;
                        ///分组为空时立马获取分组
                        if (string.IsNullOrEmpty(type))
                        {
                            //Beauty.App.BeautyService.WebGroup group = null;

                            if (string.IsNullOrEmpty(task.Type))
                            {
                                ///update group

                                string html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/magazine/user_groups", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", null, "", true, user.Cookie, null, Encoding.GetEncoding("gb2312"), null, true);
                                JavaScriptSerializer serializer = new JavaScriptSerializer();
                                List <UserGroup>     objs       = serializer.Deserialize <List <UserGroup> >(html);
                                if (objs != null && objs.Count > 0)
                                {
                                    foreach (UserGroup usergroup in objs)
                                    {
                                        if (usergroup.name.Contains(share.Keyword))
                                        {
                                            //group = new BeautyService.WebGroup { Name = usergroup.name, ID = usergroup.group_id };
                                            type = usergroup.group_id;
                                        }
                                        client.BeginUpdateGroup(user.Username, usergroup.group_id, usergroup.name, null, null);
                                    }

                                    if (string.IsNullOrEmpty(type) && objs.Count > 0)
                                    {
                                        type = objs[0].group_id;
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(type))
                        {
                            string postdata = "type=8&stid=" + bady.Twitterid + "&tContent=" + task.Comment + "&name=" + user.Username + "&group_id=" + type + "&syncToQzone=false&syncToWeibo=false";
                            string html     = HttpHelper.GetHtml("http://www.meilishuo.com/aw/twitter/create", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", postdata, true, user.Cookie, null, Encoding.UTF8, null, true);

                            JavaScriptSerializer serializer   = new JavaScriptSerializer();
                            PostShareResult      resultobject = serializer.Deserialize <PostShareResult>(html);
                            if (resultobject.code.HasValue && resultobject.code.Value == 0)
                            {
                                //client.CompleteShareTask(task.ID.ToString(), task.Taskid.ToString(), bady.ID.ToString(), obj.data.gInfo.goodsID.ToString(), resultobject.data.twitter_id.ToString(), resultobject.data.group_id.ToString());
                                client.BeginCompletelikeTask(task.ID.ToString(), like.ID.ToString(), null, null);
                                writelog("完成收录任务");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMsg = "An application error occurred. Please contact the adminstrator " +
                                  "with the following information:/n/n";
                errorMsg += ex.Message + "/n/nStack Trace:/n" + ex.StackTrace + "//" + ex.Source;
                client.BeginLog(errorMsg, null, null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 提交分享
        /// </summary>
        /// <param name="task"></param>
        public void PostShare(Beauty.App.BeautyService.WebTask task)
        {
            //http://www.meilishuo.com/aj/twitter/fetch
            try
            {
                int count = 0;

                Beauty.App.BeautyService.WebShare share = client.GetShare(task.Taskid.ToString());
                if (share != null)
                {
                    Beauty.App.BeautyService.WebBady bady = client.GetBady(share.Bady.ID.ToString());
                    string url  = System.Web.HttpUtility.UrlEncode(bady.Link);
                    string html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/twitter/fetch", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", "url=" + url, true, user.Cookie, null, Encoding.UTF8, null, true);
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    PostBadyResult       obj        = serializer.Deserialize <PostBadyResult>(html);
                    //{"error_code":0,"data":{"gInfo":{"title":"\u7c73\u897f\u679c \u7ae5\u88c5\u513f\u7ae5\u76ae\u8863\u5916\u5957\u7537\u7ae5\u79cb\u88c52013\u65b0\u6b3e\u5939\u514b\u886b\u4f11\u95f2\u5916\u5957\u6f6eSM7A7","goods_url":"http:\/\/detail.tmall.com\/item.htm?id=27015308049","image":"http:\/\/img01.taobaocdn.com\/bao\/uploaded\/i1\/14275026844061217\/T1DcimFcxgXXXXXXXX_!!0-item_pic.jpg","domain":"tmall.com","price":158,"goodsID":64628518}}}
                    //string errorcode = html.Substring(html.IndexOf(":") + 1, html.IndexOf(",") - html.IndexOf(":") - 1);
                    if (obj.data == null)
                    {
                        //提交错误时,3次重复提交
                        count++;
                        while (count < 3)
                        {
                            html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/twitter/fetch", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", bady.Link, true, user.Cookie, null, Encoding.UTF8, null, true);

                            obj = serializer.Deserialize <PostBadyResult>(html);

                            if (obj.error_code == 0)
                            {
                                break;
                            }
                            count++;
                        }
                    }

                    if (obj.error_code != 0)
                    {
                        return;
                    }

                    Beauty.App.BeautyService.WebGroup group = null;

                    ///如果分组编号为空,立马获取该用户的分组
                    if (string.IsNullOrEmpty(task.Type))
                    {
                        ///update group

                        html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/magazine/user_groups", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", null, "", true, user.Cookie, null, Encoding.GetEncoding("gb2312"), null, true);

                        List <UserGroup> objs = serializer.Deserialize <List <UserGroup> >(html);
                        if (objs != null && objs.Count > 0)
                        {
                            foreach (UserGroup usergroup in objs)
                            {
                                if (usergroup.name.Contains(share.Keyword))
                                {
                                    group = new BeautyService.WebGroup {
                                        Name = usergroup.name, ID = usergroup.group_id
                                    };
                                }
                                client.BeginUpdateGroup(user.Username, usergroup.group_id, usergroup.name, null, null);
                            }

                            if (group == null && objs.Count > 0)
                            {
                                group = new BeautyService.WebGroup {
                                    Name = objs[0].name, ID = objs[0].group_id
                                };
                            }
                        }
                    }
                    else
                    {
                        group = client.GetGroup(task.Type);
                    }

                    //创建新分组
                    if (!string.IsNullOrEmpty(task.NewType))
                    {
                        string groupid = CreateGroup(task.NewType);
                        if (groupid != null)
                        {
                            client.BeginUpdateGroup(user.Username, groupid, task.NewType, null, null);
                            group = new BeautyService.WebGroup {
                                Name = task.NewType, ID = groupid
                            };
                        }
                    }

                    //分组不为空才能提交
                    if (group != null)
                    {
                        if (obj.data != null)
                        {
                            string postdata = "type=7&goodsID=" + obj.data.gInfo.goodsID + "&group_id=" + task.Type + "&name=" + group.Name + "&tContent=" + task.Comment + "&goods_pic_url=" + obj.data.gInfo.image + "&syncToQzone=false&syncToWeibo=false";
                            //string goodid = html.Substring(html.LastIndexOf(":") + 1, html.IndexOf("}") - html.LastIndexOf(":") - 1);
                            //{"code":0,"data":{"twitter_id":1739748392,"group_id":42454433}}
                            html = HttpHelper.GetHtml("http://www.meilishuo.com/aw/twitter/create", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", postdata, true, user.Cookie, null, Encoding.UTF8, null, true);

                            PostShareResult resultobject = serializer.Deserialize <PostShareResult>(html);
                            if (resultobject.code == 0)
                            {
                                writelog("完成分享任务");
                                client.BeginCompleteShareTask(task.ID.ToString(), task.Taskid.ToString(), bady.ID.ToString(), obj.data.gInfo.goodsID.ToString(), resultobject.data.twitter_id.ToString(), resultobject.data.group_id.ToString(), null, null);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMsg = "An application error occurred. Please contact the adminstrator " +
                                  "with the following information:/n/n";
                errorMsg += ex.Message + "/n/nStack Trace:/n" + ex.StackTrace + "//" + ex.Source;
                client.BeginLog(errorMsg, null, null);
            }
        }