XF 2.2 User API Keys

Tapple

New member
I have done a lot of digging around the API endpoints, and I don't see a way to programmatically generate API keys. I want to create a mobile app for my forum, but from what I have seen so far, you cannot create a forum post or thread as another user, unless you are using an API key with that user associated with it. Is there anyway to create an API key for the user if they dont already have on upon login for instance? If not, has anyone found out a way in which I can make this app happen without manually creating an API key for each user? Any addons or custom scripts? Need about 3.5k keys for my users.
 

MesterPerfect

Active member
look here
 

robdog

Well-known member
PHP:
$apiKey = $this->em()->create('XF:ApiKey');

$keyScopes = [
    // SET YOUR API SCOPES HERE.
];

$keyManager = $this->service('XF:ApiKey\Manager', $apiKey);
$keyManager->setTitle('Auto Key: ' . \XF::visitor()->username);
$keyManager->setActive(true);
$keyManager->setScopes(false, $keyScopes);
$keyManager->setKeyType('user', \XF::visitor()->username);
$keyManager->save();
 
Top