コード例 #1
0
        private void fetchUserInfo()
        {
            userProfilePictureBox.LoadAsync(m_LoggedInUser.PictureSqaureURL);
            userProfilePictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
            usernameLabel.Text             = m_LoggedInUser.Name;
            usernameLabel.ForeColor        = Color.FromArgb(75, 150, 236);
            usernameLabel.Font             = new Font("Arial", 16);
            showAllControls(true);

            if (m_LoggedInUser.Posts.Count > 0)
            {
                listBoxFriends.Items.Clear();
                listBoxFriends.DisplayMember = "Name";

                listBoxPosts.BeginUpdate();

                foreach (Post post in m_LoggedInUser.Posts)
                {
                    PostWrapper myPost = new PostWrapper(post);
                    listBoxPosts.Items.Add(myPost);
                }

                listBoxPosts.EndUpdate();
                listBoxFriends.BeginUpdate();

                foreach (User friend in m_LoggedInUser.Friends)
                {
                    listBoxFriends.Items.Add(friend);
                }

                listBoxFriends.EndUpdate();
            }
        }
コード例 #2
0
    public IEnumerator LoadPost(List <string> votedIds, Action showPost)
    {
        yield return(GetAccessToken());

        if (token == null)
        {
            showPost();
            yield break;
        }

        if (AllLoadedPosts.Count > 0)
        {
            PickNewPost();
            yield return(LoadComments());

            showPost();
            yield break;
        }

        AllLoadedPosts.Clear();

        UnityWebRequest www = UnityWebRequest.Get("https://oauth.reddit.com/" + postFilters + "/.json?limit=100");

        www.SetRequestHeader("Authorization", "Bearer " + token);

        if (customUserAgent && Application.platform != RuntimePlatform.WebGLPlayer)
        {
            www.SetRequestHeader("User-Agent", userAgent);
        }

        //Debug.Log("Loading posts with filter '" + postFilters + "'");

        yield return(www.Send());

        if (!www.isNetworkError)
        {
            string resultContent = www.downloadHandler.text;
            postsJSON = resultContent;

            //Debug.Log(resultContent);

            try
            {
                PostWrapper jsonValidation = JsonUtility.FromJson <PostWrapper>(resultContent);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                showPost();
                yield break;
            }

            PostWrapper json = JsonUtility.FromJson <PostWrapper>(resultContent);

            if (json.message != null)
            {
                errorMessage = "Error: " + json.message;
                showPost();
                yield break;
            }

            foreach (var p in json.data.children)
            {
                if (!votedIds.Contains(p.data.id))
                {
                    AllLoadedPosts.Add(p.data);
                }
            }

            Debug.Log("Loaded " + AllLoadedPosts.Count + " posts.");

            //Debug.Log("--------");
            //Debug.Log(post.score + " : " + post.author + " : " + post.title);
            //Debug.Log("--------");

            if (AllLoadedPosts.Count == 0)
            {
                postFilters = "r/random";
                yield return(LoadPost(votedIds, showPost));

                yield break;
            }

            PickNewPost();

            yield return(LoadComments());

            showPost();
        }
        else
        {
            errorMessage = "Network error: " + www.error;
        }
    }