3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Twitter\Account;
24 use Friendica\Module\BaseApi;
26 use Friendica\Model\Photo;
27 use Friendica\Network\HTTPException;
30 * updates the profile image for the user (either a specified profile or the default profile)
32 * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image
34 class UpdateProfileImage extends BaseApi
36 protected function post(array $request = [])
38 BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
39 $uid = BaseApi::getCurrentUserID();
41 // get mediadata from image or media (Twitter call api/account/update_profile_image provides image)
42 if (!empty($_FILES['image'])) {
43 $media = $_FILES['image'];
44 } elseif (!empty($_FILES['media'])) {
45 $media = $_FILES['media'];
48 // error if image data is missing
50 throw new HTTPException\BadRequestException('no media data submitted');
53 // save new profile image
54 $resource_id = Photo::uploadAvatar($uid, $media);
55 if (empty($resource_id)) {
56 throw new HTTPException\InternalServerErrorException('image upload failed');
60 $skip_status = $this->getRequestValue($request, 'skip_status', false);
62 $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();
64 // "verified" isn't used here in the standard
65 unset($user_info['verified']);
67 // "uid" is only needed for some internal stuff, so remove it from here
68 unset($user_info['uid']);
70 $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);