我试图在Twitter中使用banner.json更新横幅图像。在查询参数中,可以使用2种格式类型发送图像。作为base64或原始数据。
当我用base64编码我的图像时,我认为它的大小超过了最大http长度。作为二进制文件发送似乎更不合逻辑,因为它比base64长。
Post "https://api.twitter.com/1.1/account/update_profile_banner.json?banner=%2F9j%2F2wCEAA...": http2: server sent GOAWAY and closed the connection; LastStreamID=7, ErrCode=COMPRESSION_ERROR, debug=""我使用的库是达布尔/推特,但是我必须创建一个分叉,因为没有更新配置文件横幅的方法。我将以下函数和结构添加到accounts.go文件中。
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)
}UpdateProfileBannerPhoto()函数返回上述错误消息。
发布于 2022-07-14 01:17:24
解决了这个问题。粗心大意!
我了解到Twitter使用了媒体/上载方法,然后通过跟踪网络流量将其发送到标语方法来更新media_id值。
但这是不需要的。我用QueryStruct更新了UpdateProfileBannerPhoto函数中的BodyForm,解决了问题.
固定:
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)
}https://stackoverflow.com/questions/72968242
复制相似问题