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

Media upload fails when user wants to decode json as array #756

Closed
le0m opened this issue Jan 30, 2019 · 6 comments
Closed

Media upload fails when user wants to decode json as array #756

le0m opened this issue Jan 30, 2019 · 6 comments
Labels

Comments

@le0m
Copy link

le0m commented Jan 30, 2019

Hello, I found this bug because in my codebase I set the library to decode json responses as array with setDecodeJsonAsArray(true).

Doing so breaks the chunked media upload, because it consists of multiple separate calls and the method uploadMediaChunked() internally gives for granted that responses are stdClass objects.

see PR #755

@abraham
Copy link
Owner

abraham commented Jan 30, 2019

Interesting. Thanks for the PR. I'm wondering if maybe it would be better to allow http and makeRequests accept a boolean value to override $this->decodeJsonAsArray instead of casting.

@le0m
Copy link
Author

le0m commented Jan 31, 2019

I agree with you that casting is not the best solution. Did the CI build fail because of this?

I used casting because uploadMediaChunked is the only method with this problem (other methods directly return Twitter responses), and it was the fastest solution for my usecase.
Adding a parameter to http and makeRequest would work, but beware that both already accept a json parameter used for making requests.

@abraham
Copy link
Owner

abraham commented Jan 31, 2019

Currently the tests hit the live Twitter API so Travis will only run them when I create the PRs to avoid anyone from exfiltrating the credentials. #671 will fix this.

I'm not sure yet if overriding decodeJsonAsArray is the right pattern but I also don't like casting types.

@le0m
Copy link
Author

le0m commented Feb 1, 2019

This is the makeRequests method

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

it could be something like this:

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

and then in all API methods return $this->getLastBody().
The point is to separate the encoding used internally (in case the library itself needs to access a response parameter) from the encoding for the user.

@abraham abraham added the Explore label Aug 3, 2019
@merkushin
Copy link

The problem is still actual :)

@abraham
Copy link
Owner

abraham commented Jul 24, 2023

TwitterOAuth is in maintenance mode and major improvements are no longer planned. #1188

@abraham abraham closed this as completed Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants