Ejemplo n.º 1
0
        public async static Task ShareFeed(string FeedID, string text, string permission, bool commentable, List <string> with_ids, List <string> trust_ids)
        {
            text = text.Replace("\"", "\\\"");
            text = text.Replace("\r\n", "\\n");
            text = text.Replace("\n", "\\n");
            text = text.Replace("\r", "\\n");
            string         requestURI = "https://story.kakao.com/a/activities/" + FeedID + "/share";
            HttpWebRequest webRequest = GenerateDefaultProfile(requestURI, "POST");

            List <QuoteData> rawContent  = GlobalHelper.GetQuoteDataFromString(text);
            string           textContent = Uri.EscapeDataString(JsonConvert.SerializeObject(rawContent).Replace("\"id\":null,", ""));

            string postData = "content=" + textContent
                              + "&permission=" + permission + "&comment_all_writable=" + (commentable ? "true" : "false")
                              + "&is_must_read=false&enable_share=true";

            if (with_ids.Count > 0)
            {
                postData += "&with_tags=" + Uri.EscapeDataString(JsonConvert.SerializeObject(with_ids));
            }
            if (trust_ids.Count > 0)
            {
                postData += "&allowed_profile_ids=" + Uri.EscapeDataString(JsonConvert.SerializeObject(trust_ids));
            }

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            Stream writeStream = await webRequest.GetRequestStreamAsync();

            writeStream.Write(byteArray, 0, byteArray.Length);
            writeStream.Close();

            await GetResponseFromRequest(webRequest);
        }
Ejemplo n.º 2
0
        public async static Task ReplyToFeed(string FeedID, string text, string id, string name, UploadedImageProp img = null)
        {
            text = text.Replace("\"", "\\\"");
            text = text.Replace("\r\n", "\\n");
            text = text.Replace("\n", "\\n");
            text = text.Replace("\r", "\\n");
            string requestURI = "https://story.kakao.com/a/activities/" + FeedID + "/comments";

            if (id != null && name != null)
            {
                text = text.Insert(0, "{!{{" + "\"id\":\"" + id + "\", \"type\":\"profile\", \"text\":\"" + name + "\"}}!} ");
            }

            List <QuoteData> rawContent  = GlobalHelper.GetQuoteDataFromString(text, true);
            string           textContent = Uri.EscapeDataString(JsonConvert.SerializeObject(rawContent).Replace("\"id\":null,", ""));

            string postData;
            string imageData  = "";
            string imageData2 = "";
            string textNow    = GlobalHelper.GetStringFromQuoteData(rawContent, false);

            if (img != null)
            {
                imageData2  = "(Image) ";
                imageData   = "{\"media_path\":\"" + img.access_key + "/" + img.info.original.filename + "?width=" + img.info.original.width + "&height=" + img.info.original.height + "&avg=" + img.info.original.avg + "\",\"type\":\"image\",\"text\":\"(Image) \"},";
                textContent = textContent.Insert(3, Uri.EscapeDataString(imageData));
            }

            postData = "text=" + Uri.EscapeDataString(imageData2 + textNow) + "&decorators=" + textContent;

            postData = postData.Replace("%20", "+");

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);


            HttpWebRequest webRequest = GenerateDefaultProfile(requestURI, "POST");

            Stream writeStream = await webRequest.GetRequestStreamAsync();

            writeStream.Write(byteArray, 0, byteArray.Length);
            writeStream.Close();

            await GetResponseFromRequest(webRequest);
        }
Ejemplo n.º 3
0
        public static async Task EditComment(Comment comment, string text, PostData data)
        {
            string requestURI = "https://story.kakao.com/a/activities/" + data.id + "/comments/" + comment.id + "/content";

            List <QuoteData> rawContent  = GlobalHelper.GetQuoteDataFromString(text);
            string           textContent = Uri.EscapeDataString(JsonConvert.SerializeObject(rawContent).Replace("\"id\":null,", ""));

            string imageData  = "";
            string imageData2 = "";

            foreach (QuoteData qdata in comment.decorators)
            {
                if (qdata.media_path != null)
                {
                    imageData2 = "(Image) ";
                    imageData  = JsonConvert.SerializeObject(qdata, Formatting.None, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });
                    textContent = textContent.Insert(3, Uri.EscapeDataString(imageData));
                }
            }
            string postData = "text=" + Uri.EscapeDataString(imageData2 + GlobalHelper.GetStringFromQuoteData(rawContent, false));

            postData += "&decorators=" + textContent;

            postData = postData.Replace("%20", "+");

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            HttpWebRequest webRequest = GenerateDefaultProfile(requestURI, "PUT");

            Stream writeStream = await webRequest.GetRequestStreamAsync();

            writeStream.Write(byteArray, 0, byteArray.Length);
            writeStream.Close();

            await GetResponseFromRequest(webRequest);
        }
Ejemplo n.º 4
0
        private async Task <bool> WriteText(string text, string permission, bool isCommentable, bool isSharable)
        {
            text = text.Replace("\"", "\\\"");
            text = text.Replace("\r\n", "\\n");
            text = text.Replace("\n", "\\n");
            text = text.Replace("\r", "\\n");
            string           commentable = isCommentable ? "true" : "false";
            string           sharable    = isSharable ? "true" : "false";
            List <QuoteData> rawContent  = GlobalHelper.GetQuoteDataFromString(text);
            string           textContent = Uri.EscapeDataString(JsonConvert.SerializeObject(rawContent, Formatting.None, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));
            StringBuilder postDataBuilder = new StringBuilder();

            postDataBuilder.Append("permission=" + permission + "&comment_all_writable=" + commentable + "&is_must_read=false&enable_share=" + sharable);
            postDataBuilder.Append("&content=" + textContent);

            if (with_ids.Count > 0)
            {
                postDataBuilder.Append("&with_tags=" + Uri.EscapeDataString(JsonConvert.SerializeObject(with_ids)));
            }
            if (trust_ids.Count > 0)
            {
                postDataBuilder.Append("&allowed_profile_ids=" + Uri.EscapeDataString(JsonConvert.SerializeObject(trust_ids)));
            }

            if (mediaText != null)
            {
                postDataBuilder.Append("&" + Uri.EscapeDataString("media") + "=" + Uri.EscapeDataString(mediaText));
            }
            foreach (string mediaPath in editOldMediaPath)
            {
                postDataBuilder.Append("&" + Uri.EscapeDataString("old_media_path[]") + "=" + Uri.EscapeDataString(mediaPath));
            }

            if (linkData != null)
            {
                postDataBuilder.Append("&scrap_content=" + Uri.EscapeDataString(linkData));
            }

            assets.Clear();

            string postData = postDataBuilder.ToString();

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            string requestURI = "https://story.kakao.com/a/activities";

            if (isEdit)
            {
                requestURI = "https://story.kakao.com/a/activities/" + editFeedID + "/content";
            }

            HttpWebRequest request = WebRequest.CreateHttp(requestURI);

            request.Method = "POST";
            if (isEdit)
            {
                request.Method = "PUT";
            }
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

            request.CookieContainer = WebViewWindow.GetUriCookieContainer(new Uri("https://story.kakao.com"));
            request.Headers["X-Kakao-DeviceInfo"] = "web:d;-;-";
            request.Headers["X-Kakao-ApiLevel"]   = "46";
            request.Headers["X-Requested-With"]   = "XMLHttpRequest";
            request.Headers["X-Kakao-VC"]         = "185412afe1da9580e67f";
            request.Headers["Cache-Control"]      = "max-age=0";

            request.Headers["Accept-Encoding"] = "gzip, deflate, br";
            request.Headers["Accept-Language"] = "ko";

            request.Headers["DNT"] = "1";

            request.Headers["authority"] = "story.kakao.com";
            request.Referer               = "https://story.kakao.com";
            request.KeepAlive             = true;
            request.UseDefaultCredentials = true;
            request.Host      = "story.kakao.com";
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
            request.Accept    = "application/json";

            Stream writeStream = await request.GetRequestStreamAsync();

            writeStream.Write(byteArray, 0, byteArray.Length);

            var readStream = await request.GetResponseAsync();

            var respReader = readStream.GetResponseStream();

            await(new StreamReader(respReader, Encoding.UTF8)).ReadToEndAsync();
            respReader.Close();

            return(true);
        }