I am trying to update banner image using account/update_profile_banner.json in Twitter API. In the query parameter, it is said that the image can be sent in 2 format types. as base64 or raw data.
When I encode my image with base64, I think its size exceeds the maximum http length. Sending as binary seems more illogical as it would be longer than base64.
Post "https://api.twitter.com/1.1/account/update_profile_banner.json?banner=/9j/2wCEAA...": http2: server sent GOAWAY and closed the connection; LastStreamID=7, ErrCode=COMPRESSION_ERROR, debug=""
The library I use is dghubble/go-twitter, but I had to create a fork since there is no method to update the profile banner. I added the following function and struct to the accounts.go file.
type AccountUpdateProfileBannerPhotoParams struct {
Banner string `url:"banner,omitempty"`
Width int `url:"width,omitempty"`
Height int `url:"height,omitempty"`
OffsetX int `url:"offset_left,omitempty"`
OffsetY int `url:"offset_top,omitempty"`
}
func (s *AccountService) UpdateProfileBannerPhoto(params *AccountUpdateProfileBannerPhotoParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Post("update_profile_banner.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
The UpdateProfileBannerPhoto()
function returns the above error message.
CodePudding user response:
Resolved the problem. Carelessness!
I learned that Twitter used the media/upload method and then updated the media_id
value by sending it to the account/update_profile_banner method by following the network traffic.
But it is not needed. I updated the QueryStruct
in the UpdateProfileBannerPhoto
function with BodyForm
and the problem was solved...
Fixed:
func (s *AccountService) UpdateProfileBannerPhoto(params *AccountUpdateProfileBannerPhotoParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Post("update_profile_banner.json").BodyForm(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}