Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm quite desperate, I working on project when I'd like to impersotane users and create post on behalf of them, read theirs feeds and according of those do some actions. I have figured out how to post on another user newsfeed, but still cannot read all. I have tried function GetFeedFor(), but this give you back just threads, no likes, no follows. I have been trying impersonate the process accordingly:

using (SPSite site = new SPSite(myHostUrl))
            {
                SPUser userForContext = site.RootWeb.SiteUsers[account2];
                SPUserToken userToken = userForContext.UserToken;
                //create service context
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                //using Service Context Scope
                using (new SPServiceContextScope(serviceContext))
                {
                    //create profile manager for loading my test accounts
                    UserProfileManager profileManager = new UserProfileManager(serviceContext);
                    UserProfile userProfile = profileManager.GetUserProfile(account2);
                    /*List all NewsFeeds*/
                    SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, serviceContext, userToken);
                    //here is exception thrown away
                    SPSocialFeed feed =  feedManager.GetFeed(SPSocialFeedType.Personal, new SPSocialFeedOptions());
                    //this write post on user's newsfeed and works!
                    WritePost(feedManager, "Forth Test!");
                }
            }

Whole stack is here:

Microsoft.Office.Server.Social.SPSocialException was unhandled
  HResult=6
  Message=The operation failed because an internal error occurred. Internal type name: Microsoft.Office.Server.Microfeed.MicrofeedException. Internal error code: 58.
  Source=Microsoft.Office.Server.UserProfiles
  ErrorCode=6
  InternalErrorCode=58
  InternalMessage=ServerErrorSecurityTrimmer : No Security Trimmer found  : Correlation ID:00000000-0000-0000-0000-000000000000 : Date and Time : 13/09/2013 16:44:27
  InternalStackTrace=   at Microsoft.Office.Server.Microfeed.MicroBlogEntity.SecurityTrimMicroFeed(List`1 mbThreads, SPMicrofeedRetrievalOptions retrievalOptions)
   at Microsoft.Office.Server.Microfeed.SPMicrofeedThreadCollection.SecurityTrimMicroFeed(SPMicrofeedRetrievalOptions retrievalOptions)
   at Microsoft.Office.Server.Microfeed.SPMicrofeedThreadCollection.Populate(SPMicrofeedRetrievalOptions retrievalOptions, SPMicrofeedContext context)
   at Microsoft.Office.Server.Microfeed.SPMicrofeedManager.CommonGetFeedFor(SPMicrofeedRetrievalOptions retrievalOptions)
   at Microsoft.Office.Server.Microfeed.SPMicrofeedManager.CommonPubFeedGetter(SPMicrofeedRetrievalOptions feedOptions, MicrofeedPublishedFeedType feedType, Boolean publicView)
   at Microsoft.Office.Server.Microfeed.SPMicrofeedManager.GetMyPublishedFeed(SPMicrofeedRetrievalOptions feedOptions, MicrofeedPublishedFeedType typeOfPubFeed, Boolean ShowPublicView)
   at Microsoft.Office.Server.Social.SPSocialFeedManager.Microsoft.Office.Server.Social.ISocialFeedManagerProxy.ProxyGetFeed(SPSocialFeedType type, SPSocialFeedOptions options)
   at Microsoft.Office.Server.Social.SPSocialFeedManager.c__DisplayClass2b.b__2a(ISocialFeedManagerProxy proxy)
   at Microsoft.Office.Server.Social.SPSocialFeedManager.c__DisplayClass4b`1.b__4a()
   at Microsoft.Office.Server.Social.SPSocialUtil.InvokeWithExceptionTranslation[T](ISocialOperationManager target, String name, Func`1 func)
  InternalTypeName=Microsoft.Office.Server.Microfeed.MicrofeedException
  StackTrace:
       at Microsoft.Office.Server.Social.SPSocialUtil.TryTranslateExceptionAndThrow(Exception exception)
       at Microsoft.Office.Server.Social.SPSocialUtil.InvokeWithExceptionTranslation[T](ISocialOperationManager target, String name, Func`1 func)
       at Microsoft.Office.Server.Social.SPSocialFeedManager.S2SInvoke[T](String name, SPS2SAppExecutionContextBase context, Func`2 func, Boolean elevateForIsLocalCheck)
       at Microsoft.Office.Server.Social.SPSocialFeedManager.c__DisplayClass48`1.b__47()
       at Microsoft.Office.Server.Social.SPSocialUtil.InvokeWithExceptionTranslation[T](ISocialOperationManager target, String name, Func`1 func)
       at Microsoft.Office.Server.Social.SPSocialFeedManager.S2SInvoke[T](String name, MicroBlogEntity mbeTarget, Func`2 func, Boolean elevateForIsLocalCheck)
       at Microsoft.Office.Server.Social.SPSocialFeedManager.GetFeed(SPSocialFeedType type, SPSocialFeedOptions options)
       at SocialTest.CreatePost.Program.Main(String[] args) in c:\Users\m.bodocky\Documents\Visual Studio 2012\Projects\SocialTest\SocialTest.CreatePost\Program.cs:line 54
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Thank you for any advice!

share|improve this question
    
Hello, I'd like to ask MS guys to comment functions, especially for using user contexts. The failure of my program is in using the constructor: SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, serviceContext, userToken); => userProfile - is user profile of user who's running this application; serviceContext - is from your my site collection; userToken - is user token of user which is object of your query! –  Martin Bodocky Sep 16 '13 at 7:59
    
Hello,<br/>this code does not work for me. It does not throw an exception but I always get the feed of the current user, no matter what UserToken I'm sending. I can test this behavior by running the code in a console app as different Windows users. I always get the feed of the user account the console is started with. > Might this be a bug in SharePoint's social API? Best regards<br/> Holger –  mrhoga Jan 8 at 21:25

1 Answer 1

up vote 0 down vote accepted

This is working solution:

using (SPSite site = new SPSite(myHostUrl))
            {
                //account1 is not current user
                SPUser userForContext = site.RootWeb.SiteUsers[account1];
                SPUserToken userToken = userForContext.UserToken;
                //create service context
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                //using Service Context Scope
                using (new SPServiceContextScope(serviceContext))
                {
                    //create profile manager for loading my test accounts
                    UserProfileManager profileManager = new UserProfileManager(serviceContext);
                    // I'm getting user profile of my current user
                    UserProfile userProfile = profileManager.GetUserProfile(System.Environment.UserName);
                    SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, serviceContext, userToken);
                    //It does work nicely!
                    SPSocialFeed feed =  feedManager.GetFeed(SPSocialFeedType.Personal, new SPSocialFeedOptions());
                }
            }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.