API question: create a new thread and set author?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • musicoff
    Member
    • Jan 2017
    • 86
    • 5.2.x

    API question: create a new thread and set author?

    Hello there, we are able to automatically create a thread in vbulletin via API, but for some reason the author is being ignored. Here's the code:

    Code:
    $api->callApi('content_text', 'add', [
        'data' => [
            'publisheddate' => $time,
            [b]'userid' => 1 \\ <--- this is ignored
            'authorname' => 'admin' \\ <--- this is ignored[/b]
            'description' => 'test',
            'pagetext' => '',
            'rawtext' => $rawText,
            'title' => $title,
            'htmltitle' => $title,
            'parentid' => env('VBULLETIN_POST_PARENTID'),
            'created' => $time,
            'lastcontent' => $time,
            [b]'lastcontentauthor' => 'admin' \\ <--- this is ignored
            'lastauthorid' => 1 \\ <--- this is ignored[/b]
        ],
    ]);
    The thread is properly added, but the author is set as the currently logged in user. How can we fix this?

    Thank you.
  • glennrocksvb
    Former vBulletin Developer
    • Mar 2011
    • 4021
    • 5.7.X

    #2
    You have to create a new user session using the userid and set it as the current session before calling the API. Then after calling the API, restore the original session.

    Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

    Comment


    • southstar86
      southstar86 commented
      Editing a comment
      I know this post is kind of old, but I currently dealing with this. Would you be able to be more specific about how to achieve this?

      I am allowing users to log in from my main site to VB using the API and that works fine.
      I am trying to build functionality to add a forum post as a different user, without messing up the current user's login.

      If i call the login method as the admin user, I can add that post. As long as I don't overwrite the cookies, visiting the forums will still show the original non-admin user as being logged in. However, all further API calls from the main site seem to now be set to the admin user instead, and I like them to remain scoped to the non-admin user.

      I am confused as to when api.init needs to called, and what exactly that is doing.

      I've tried various things, but either the API sees the admin user as being the current user, or the API throws invalid access token errors.

      Thanks in advance
  • Paul M
    Former Lead Developer
    vB.Com & vB.Org
    • Sep 2004
    • 9886

    #3
    You could also request a hook be added so that you can set the values before save (or you might be able to write an extension that does it).
    (A hook may already exist, I dont have access to see atm, plus of course, this is assuming this is for use on your own forum).
    Baby, I was born this way

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...