Esempio n. 1
0
        /**
         * Load the Chatter feed from the Chatter REST API, and add to the data source
         **/
        private async void LoadChatterFeed()
        {
            SFDCRestApi sfdcRest = new SFDCRestApi();
           // sfdcRest.GenerateDummyData();

            ChatterFeedDataSource chatterFeedDataSource = (ChatterFeedDataSource)App.Current.Resources["chatterFeedDataSource"];

            this.DefaultViewModel["Items"] = chatterFeedDataSource.Items;          

            JObject responseObject = await sfdcRest.Request("GET", "chatter/feeds/news/me/feed-items?pageSize=100");

            JArray responseItems = (JArray)responseObject["items"];

            foreach (JObject itemObject in (JArray)responseObject["items"])
            {
                Debug.WriteLine((string)itemObject["body"]["text"]);

                ChatterFeedItem feedItem = new ChatterFeedItem();
                feedItem.Id = (string)itemObject["id"];
                feedItem.Content = WebUtility.HtmlDecode((string)itemObject["body"]["text"]);
                feedItem.Title = WebUtility.HtmlDecode(StringUtil.TruncateAtWord(feedItem.Content, 50));
                feedItem.AuthorName = WebUtility.HtmlDecode((string)itemObject["actor"]["name"]);
                feedItem.GroupName = WebUtility.HtmlDecode((string)itemObject["parent"]["name"]);
                feedItem.CreatedDate = ((DateTime)itemObject["createdDate"]).ToString();
                feedItem.Image = (string)itemObject["actor"]["photo"]["largePhotoUrl"]+"?oauth_token="+SFDCSession.Instance.AccessToken;
                feedItem.Comments = new List<ChatterFeedItemComment>();
                foreach (JObject commentObject in itemObject["comments"]["comments"])
                {
                    ChatterFeedItemComment feedItemComment = new ChatterFeedItemComment();
                    feedItemComment.AuthorName = WebUtility.HtmlDecode((string)commentObject["user"]["name"]);
                    feedItemComment.Id = (string)commentObject["id"];
                    feedItemComment.Image = (string)commentObject["user"]["photo"]["largePhotoUrl"] + "?oauth_token=" + SFDCSession.Instance.AccessToken;
                    feedItemComment.CreatedDate = ((DateTime)commentObject["createdDate"]).ToString();
                    feedItemComment.Content = WebUtility.HtmlDecode((string)commentObject["body"]["text"]);
                    feedItem.Comments.Add(feedItemComment);
                }

                chatterFeedDataSource.Items.Add(feedItem);
            }
        }
Esempio n. 2
0
 /**
  * Refresh the Access Token using the Refresh Token Flow
  **/
 public async Task<String> RefreshTokenFlow()
 {
     if (InstanceUrl == null || InstanceUrl == "")
     {
         InstanceUrl = PersistData.GetSerializedStringValue("instance_url");
     }
     //if we don't have a refresh token, we can't do much -- return null
     if (RefreshToken == null || RefreshToken == "")
     {
         return null;
     }
     else
     {
         SFDCRestApi sfdcRestApi = new SFDCRestApi();
         JObject responseObject = await sfdcRestApi.Request("POST", 
                                                            "https://login.salesforce.com/services/oauth2/token", 
                                                            string.Format("grant_type=refresh_token&client_id={0}&refresh_token={1}", 
                                                            ConsumerKey,
                                                            RefreshToken));
         AccessToken = (string)responseObject["access_token"];
         InstanceUrl = (string)responseObject["instance_url"];
         return AccessToken;
     }
 }