Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get file from DM #940

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/TwitterOAuth.php
Expand Up @@ -317,6 +317,19 @@ public function mediaStatus(string $media_id)
);
}

/**
* Get media file attached to direct message.
*
* @param string $url
* @param array $parameters
*
* @return string
*/
public function getFile(string $url, array $parameters = [])
{
return $this->makeRequests($url, 'GET', $parameters, false);
}

/**
* Private method to upload media (not chunked) to upload.twitter.com.
*
Expand Down Expand Up @@ -464,7 +477,12 @@ private function http(
if (!$json) {
$parameters = $this->cleanUpParameters($parameters);
}
return $this->makeRequests($url, $method, $parameters, $json);
$result = $this->makeRequests($url, $method, $parameters, $json);

$response = JsonDecoder::decode($result, $this->decodeJsonAsArray);
$this->response->setBody($response);

return $response;
}

/**
Expand All @@ -477,7 +495,7 @@ private function http(
* @param array $parameters
* @param bool $json
*
* @return array|object
* @return string
*/
private function makeRequests(
string $url,
Expand All @@ -488,13 +506,11 @@ private function makeRequests(
do {
$this->sleepIfNeeded();
$result = $this->oAuthRequest($url, $method, $parameters, $json);
$response = JsonDecoder::decode($result, $this->decodeJsonAsArray);
$this->response->setBody($response);
$this->attempts++;
// Retry up to our $maxRetries number if we get errors greater than 500 (over capacity etc)
} while ($this->requestsAvailable());

return $response;
return $result;
}

/**
Expand Down