Closed punkeel closed 8 years ago
@PunKeel First of all, thank you very much for your extensive report. This will help to find the reason for the failing media post. I’ll take a close look at what happens and get back to you afterwards.
What does the following code show?
$reply = $cb->media_upload(
array(
'media' => $imageUrl
)
);
var_dump($reply);
With the URL given:
object(stdClass)#113 (4) {
["request"]=>
string(22) "/1.1/media/upload.json"
["error"]=>
string(24) "media type unrecognized."
["httpstatus"]=>
int(400)
["rate"]=>
object(stdClass)#111 (3) {
["limit"]=>
string(3) "415"
["remaining"]=>
string(3) "414"
["reset"]=>
string(10) "1452110187"
}
}
With relative file path:
object(stdClass)#113 (7) {
["media_id"]=>
int(684810997559881728)
["media_id_string"]=>
string(18) "684810997559881728"
["size"]=>
int(310060)
["expires_after_secs"]=>
int(86400)
["image"]=>
object(stdClass)#111 (3) {
["image_type"]=>
string(9) "image/png"
["w"]=>
int(700)
["h"]=>
int(400)
}
["httpstatus"]=>
int(200)
["rate"]=>
object(stdClass)#153 (3) {
["limit"]=>
string(3) "415"
["remaining"]=>
string(3) "413"
["reset"]=>
string(10) "1452110187"
}
}
... My bad. I var_dump'ed the downloaded file content (line 1802 in codebird.php), and ... 403 Forbidden.
I block everything with a "PHP" user agent ... Meaning Twitter/FB can still reach the webserver, but "codebird-php" can't
Sorry for the useless report (unless you turn it into a "throw exception if media download fails" ?)
Maybe you’d like to add our user agent to the whitelist?
It’s codebird-php/3.0.0 +https://github.com/jublonet/codebird-php
currently, but expect the version to increment, like 3.1.0-dev
or 3.1.0-rc.1
. This regex would match:
/^codebird-php\/[1-9]\d*\.\d+\.\d+(-([a-z]+\.[1-9]\d*|dev))? \+/
@PunKeel Please test if failing remote media downloads now throw an Exception.
Not tested but I don't think this would work, I put my var_dump right before that line: https://github.com/jublonet/codebird-php/blob/9c9a5206d9f32d1e6d5b4e94f6698e8799af2338/src/codebird.php#L1827
@PunKeel I have amended the code and added unit tests for it, can you verify?
Working fine, thanks!
Great! This feature is going to be included in Codebird-PHP 3.1.0.
What about the User-Agent whitelisting?
Disabled on my side, there's no real reason for it (legacy config to block bots) :)
Hello,
I've received an error when trying to upload an image from an URL:
Quite sure it worked before 3.0.
URL:
https://epicube.fr/files/article/3853080-ragecraft.png
(certificate by LetsEncrypt) Error from the API:unknown media type
Workaround: using the local file path instead.
Note: The same URL is used for the Facebook/Twitter thumbnail, so I don't think it comes from the image/webserver.
If you need more information, just tell me :) (I'll try to see if I find the origin)
Version used: 9d78f88e76f11b4595f2dc0f3a54ff3a9addbed6, PHP5