コード例 #1
0
        public static async Task <IList <string> > FetchMessageFromAPIAsync(string target, int offset = 0)
        {
            IList <string> list = new List <string>();

            try {
                var result = await DoubanWebProcess.GetMDoubanResponseAsync(target, client : new Windows.Web.Http.HttpClient());

                if (result == null)
                {
                    return(list);
                }
                JObject jo    = JObject.Parse(result);
                var     feeds = jo["recommend_feeds"];
                if (feeds == null || !feeds.HasValues)
                {
                    return(list);
                }
                if (feeds.HasValues)
                {
                    feeds.Children().Take(5).ToList().ForEach(singleton => {
                        try {
                            list.Add(singleton["title"].Value <string>());
                        } catch { /* Ignore, item error. */ }
                    });
                }
            } catch { /* Ignore */ }
            return(list);
        }
コード例 #2
0
ファイル: APITest.cs プロジェクト: miao17game/Beansprout.UWP
        public static async void TestAsync()
        {
            var result = await DoubanWebProcess.GetMDoubanResponseAsync("https://m.douban.com/rexxar/api/v2/movie/26382689/interests?count=4&order_by=hot&start=0&ck=17fl&for_mobile=1");

            JObject jo = JObject.Parse(result);

            Debug.WriteLine(jo.ToString());
        }
コード例 #3
0
ファイル: APITest.cs プロジェクト: miao17game/Beansprout.UWP
        public static async void TestAsync(bool moreMessage)
        {
            var result = await DoubanWebProcess.GetMDoubanResponseAsync(
                string.Format("https://frodo.douban.com/jsonp/subject_collection/music_chinese/items?os=windows&callback=jsonp1&start=0&count=8&loc_id=0&_={0}", (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds),
                "frodo.douban.com",
                "https://m.douban.com/music/");

            JObject jo = JObject.Parse(result.Substring(7, result.Length - 8));

            Debug.WriteLine(jo.ToString());
        }
コード例 #4
0
ファイル: APITest.cs プロジェクト: miao17game/Beansprout.UWP
        public static async void TestAsync(bool moreMessage, bool isMobile, string path, string host, string reffer, HttpFormUrlEncodedContent content)
        {
            var result = await DoubanWebProcess.PostDoubanResponseAsync(
                path,
                host,
                reffer,
                content,
                isMobile);

            JObject jo = JObject.Parse(result);

            Debug.WriteLine(jo.ToString());
        }
コード例 #5
0
 public static async Task <string> AccessOauth2Token(string email, string password)
 {
     return(await DoubanWebProcess.PostDoubanResponseAsync(
                path : "https://frodo.douban.com/service/auth2/token",
                host : "frodo.douban.com",
                reffer : null,
                content :
                new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
         new KeyValuePair <string, string>("client_id", "0dad551ec0f84ed02907ff5c42e8ec70"),
         new KeyValuePair <string, string>("client_secret", "9e8bb54dc3288cdf"),
         new KeyValuePair <string, string>("redirect_uri", "frodo://app/oauth/callback/"),
         new KeyValuePair <string, string>("grant_type", "password"),
         new KeyValuePair <string, string>("username", email),
         new KeyValuePair <string, string>("password", password),
         new KeyValuePair <string, string>("os_rom", "android"),
     }),
                isMobileDevice : true));
 }
コード例 #6
0
        private static async Task <ToastItem> FetchMessageFromAPIAsync(string target, int offset = 0)
        {
            try {
                var result = await DoubanWebProcess.GetMDoubanResponseAsync(target, client : new Windows.Web.Http.HttpClient());

                if (result == null)
                {
                    return(null);
                }
                JObject jo    = JObject.Parse(result);
                var     feeds = jo["recommend_feeds"];
                if (feeds == null || !feeds.HasValues)
                {
                    return(null);
                }
                if (feeds.HasValues)
                {
                    var now = DateTime.Now.Hour - 4;
                    if (now < 3)
                    {
                        now = 3;
                    }
                    try {
                        var single = feeds.Children().ElementAt(now);
                        var author = single["target"]["author"];
                        var uri    = UriDecoder.CreateJson(new ToastParameters {
                            Title = single["title"].Value <string>(),
                            Uri   = UriDecoder.GetUrlFromUri(single["target"]["uri"].Value <string>()),
                            Type  = EncodeFormat.ToatFromInfosList
                        });
                        return(new ToastItem {
                            Title = single["title"].Value <string>(),
                            ImageSrc = single["target"]["cover_url"].Value <string>() != "" ? single["target"]["cover_url"].Value <string>() : null,
                            LogoOverride = author.HasValues ? author["avatar"].Value <string>() != "" ? author["avatar"].Value <string>() : null : null,
                            Content = single["target"]["desc"].Value <string>() != "" ? single["target"]["desc"].Value <string>() : null,
                            Uri = uri,
                        });
                    } catch { return(null); }
                }
            } catch { /* Ignore */ }
            return(null);
        }
コード例 #7
0
        public static async Task <string> FetchTypeCollectionList(
            string headString,
            string loc_id,
            uint start,
            uint count,
            double minised,
            SubjectType type    = SubjectType.Books,
            RequestType request = RequestType.Groups)
        {
            var refer_sub_type =
                type == SubjectType.Books ? "book" :
                type == SubjectType.Movies ? "movie" :
                type == SubjectType.Music ? "music" :
                "tv";
            var formatPath = request == RequestType.SubjectCollection ? SubjectCollectionPath : TypePath;

            return(await DoubanWebProcess.GetMDoubanResponseAsync(string.Format(formatPath, new object[] { headString, start, count, loc_id, minised }),
                                                                  "m.douban.com",
                                                                  $"{"https:"}//m.douban.com/{refer_sub_type}/"));
        }