TWITTER_POSTSTATUS_2::media_upload( $media )

Send image to Automator API.


Parameters Parameters

$status

(string) (Required)


Top ↑

Return Return

(mixed)


Source Source

File: src/integrations/twitter/actions/twitter-poststatus-2.php

	public function media_upload( $media ) {

		// Get twitter credentials.
		$request_body = Automator()->helpers->recipe->twitter->get_client();

		$url = Automator()->helpers->recipe->twitter->automator_api;

		$request_body['action'] = 'media_upload';
		$request_body['media']  = $media;
		$args                   = array();
		$args['body']           = $request_body;
		$args['timeout']        = 60;

		$response = wp_remote_post( $url, $args );

		if ( is_array( $response ) && ! is_wp_error( $response ) ) {
			$body = json_decode( wp_remote_retrieve_body( $response ) );
			if ( ! isset( $body->error ) && isset( $body->data->media_id ) ) {
				return $body->data->media_id;
			} else {
				throw new \Exception( $body->error->description );
			}
		} else {
			$error_msg = $response->get_error_message();
			throw new \Exception( $error_msg );
		}

	}