如何解决Google Place Photos API 返回空数据 - Golang
我正在尝试通过其他 API 端点提供的 Google photo_reference
ID 请求获取照片。但是,它返回一个没有图像的对象。我已经设置了一个小型 API 网络服务器来接受以下负载:
# POST
{
"photo_reference": "photo-reference-id","key": "my-google-api-key"
}
我处理调用的函数:
import (
"context"
"fmt"
"googlemaps.github.io/maps"
"image"
"log"
)
type PhotoRequest struct {
PhotoReference string `json:"photo_reference"`
Key string `json:"key"`
}
func Photo(p *PhotoRequest) (maps.PlacePhotoResponse,error) {
c,err := maps.NewClient(maps.WithAPIKey(p.Key))
if err != nil {
log.Panicf("fatal error: %s",err)
}
r := &maps.PlacePhotoRequest{
PhotoReference: p.PhotoReference,MaxHeight: 600,MaxWidth: 600,}
result,err := c.PlacePhoto(context.Background(),r)
if err != nil {
log.Panicf("fatal error: %s",err)
}
fmt.Println(result)
return result,nil
}
回复:
{
"data": { "ContentType": "image/jpeg","Data": {} }
}
注意显示:处理请求的 HTTP 路由。我已经检查了请求,所有数据都是正确的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。