예제 #1
0
        public static async Task <int> PostComment(string text, string postID, string userID)
        {
            var     ticks = Other.getTicks().ToString();
            JObject json  = new JObject(
                new JProperty("activityId", postID),
                new JProperty("commentText", text),
                new JProperty("creationTimeMs", ticks),
                new JProperty("clientId", userID + ticks + "-1633881820")
                );
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = System.Net.Http.Headers.AuthenticationHeaderValue.Parse("Bearer " + await oAuth.GetAccessToken());
            client.DefaultRequestHeaders.Add("User-Agent", "google-oauth-playground");

            //string postData = "{\"activityId\":\"" + activityID + "\"}";
            HttpContent content = new StringContent(json.ToString());

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(new Uri(POST_COMMENT_API), content);

            Debug.WriteLine(await response.Content.ReadAsStringAsync());
            if (response.IsSuccessStatusCode == true)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
예제 #2
0
        static async Task <JObject> buildPost(string content, List <AclItem> list, string link, string emoticon, string reshareId, Location.Place place, string imageContent)
        {
            JObject json = new JObject(
                new JProperty("updateText", content),
                new JProperty("externalId", Other.getTicks().ToString() + ":" + PasswordGenerator(32, false)),
                new JProperty("sharingRoster", new JObject(
                                  new JProperty("sharingTargetId", _getAclItems(list))
                                  )
                              ));
            var square = (from item in list
                          where item.extraId != null
                          select item).FirstOrDefault();

            if (square != null)
            {
                json["squareStreams"] = new JArray(new JObject(new JProperty("squareId", square.id), new JProperty("streamId", square.extraId)));
            }
            if (link != null)
            {
                json["embed"] = await getMedia(link);
            }
            if (emoticon != null)
            {
                json["embed"] = new JObject(
                    new JProperty("emotishare", new JObject(
                                      new JProperty("emotion", emoticon.ToUpper()),
                                      new JProperty("url", "http://www.gstatic.com/s2/oz/images/emotishare/hdpi/" + emoticon + "_image.gif"),
                                      new JProperty("proxiedImage", new JObject(
                                                        new JProperty("imageUrl", "http://www.gstatic.com/s2/oz/images/emotishare/hdpi/" + emoticon + "_image.gif")
                                                        ))
                                      )),
                    new JProperty("thing", new JObject(
                                      new JProperty("url", "http://www.gstatic.com/s2/oz/images/emotishare/hdpi/" + emoticon + "_image.gif"),
                                      new JProperty("imageUrl", "http://www.gstatic.com/s2/oz/images/emotishare/hdpi/" + emoticon + "_image.gif"),
                                      new JProperty("name", emoticon.ToUpperInvariant())
                                      )),
                    new JProperty("type", new JArray(
                                      "EMOTISHARE",
                                      "THING")
                                  ));
            }
            if (reshareId != null)
            {
                json["resharedUpdateId"] = reshareId;
            }
            if (place != null)
            {
                /*
                 * "latitudeE7":516207510,
                 * "locationTag":"Widok, Ostrów Wielkopolski, wielkopolskie",
                 * "longitudeE7":177878380
                 *
                 */
                json["location"] = new JObject(
                    new JProperty("latitudeE7", place.latitude),
                    new JProperty("locationTag", place.locationTag),
                    new JProperty("longitudeE7", place.longitude));
            }
            if (imageContent != null)
            {
                /*
                 * "imageStatus":"1",
                 * "mediaType":"1",
                 * "timestamp":-{"creationTimestampMs":1.406375684079E12
                 * }
                 */
                json["photosShareData"] = new JObject(
                    new JProperty("mediaRef", new JArray(
                                      new JObject(
                                          new JProperty("clientAssignedUniqueId", "cs_01_" + PasswordGenerator(32, false)),
                                          new JProperty("imageData", imageContent),
                                          new JProperty("imageStatus", "1"),
                                          new JProperty("mediaType", "1")
                                          )
                                      )
                                  ));
            }
            return(json);
        }