英文:
Golang Twitter API - update_profile_banner Image COMPRESSION_ERROR
问题
我正在尝试使用Twitter API中的account/update_profile_banner.json来更新横幅图片。
在查询参数中,它说图片可以以两种格式之一发送,即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=""
我使用的库是dghubble/go-twitter,但是我不得不创建一个fork,因为没有更新个人资料横幅的方法。我在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()
函数返回上述错误消息。
英文:
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=%2F9j%2F2wCEAA...": 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.
答案1
得分: 0
解决了问题。粗心大意!
我了解到Twitter使用media/upload方法,然后通过跟踪网络流量,将media_id
值发送到account/update_profile_banner方法来更新它。
但这是不必要的。我通过在UpdateProfileBannerPhoto
函数中使用BodyForm
更新了QueryStruct
,问题得到解决...
修复后的代码如下:
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)
}
英文:
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)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论