forked from mao888/golang-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
glog "github.com/mao888/mao-glog" | ||
"gopkg.in/resty.v1" | ||
"time" | ||
) | ||
|
||
type LiftoffCampaignsRes struct { | ||
TrackerType string `json:"tracker_type"` | ||
MinOsVersion *string `json:"min_os_version"` | ||
Name string `json:"name"` | ||
AppId string `json:"app_id"` | ||
State string `json:"state"` | ||
CampaignType string `json:"campaign_type"` | ||
Id string `json:"id"` | ||
MaxOsVersion interface{} `json:"max_os_version"` | ||
StateLastChangedAt *time.Time `json:"state_last_changed_at"` | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
var ( | ||
apiKey = "bacfa09c4f" | ||
apiSecret = "U1NUhwT2c1s0GRPka9DmZg==" | ||
basicLiftoffUrl = "https://data.liftoff.io/api/v1/campaigns" | ||
) | ||
// 拼接client_id和secret,并转换为字节数组 | ||
data := []byte(apiKey + ":" + apiSecret) | ||
// 使用base64进行编码 | ||
encoded := base64.StdEncoding.EncodeToString(data) | ||
authorization := "Basic " + encoded | ||
|
||
resp, err := resty.New().SetRetryCount(3).R(). | ||
SetHeaders(map[string]string{ | ||
"Authorization": authorization, | ||
}).Get(basicLiftoffUrl) | ||
if err != nil { | ||
glog.Errorf(ctx, "Post err:%s", err) | ||
return | ||
} | ||
glog.Infof(ctx, "resp:%s", string(resp.Body())) | ||
|
||
var res []LiftoffCampaignsRes | ||
err = json.Unmarshal(resp.Body(), &res) | ||
if err != nil { | ||
glog.Errorf(ctx, "Unmarshal err:%s", err) | ||
return | ||
} | ||
glog.Infof(ctx, "res的长度:%d", len(res)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
glog "github.com/mao888/mao-glog" | ||
"gopkg.in/resty.v1" | ||
"time" | ||
) | ||
|
||
type LiftoffCreativesRes struct { | ||
PreviewUrl *string `json:"preview_url"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
CreativeType string `json:"creative_type"` | ||
FullHtmlPreviewUrl string `json:"full_html_preview_url"` | ||
CreatedAt time.Time `json:"created_at"` | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
var ( | ||
apiKey = "bacfa09c4f" | ||
apiSecret = "U1NUhwT2c1s0GRPka9DmZg==" | ||
basicLiftoffUrl = "https://data.liftoff.io/api/v1/creatives" | ||
) | ||
// 拼接client_id和secret,并转换为字节数组 | ||
data := []byte(apiKey + ":" + apiSecret) | ||
// 使用base64进行编码 | ||
encoded := base64.StdEncoding.EncodeToString(data) | ||
authorization := "Basic " + encoded | ||
|
||
resp, err := resty.New().SetRetryCount(3).R(). | ||
SetHeaders(map[string]string{ | ||
"Authorization": authorization, | ||
}).Get(basicLiftoffUrl) | ||
if err != nil { | ||
glog.Errorf(ctx, "Post err:%s", err) | ||
return | ||
} | ||
glog.Infof(ctx, "resp:%s", string(resp.Body())) | ||
|
||
var res []LiftoffCreativesRes | ||
err = json.Unmarshal(resp.Body(), &res) | ||
if err != nil { | ||
glog.Errorf(ctx, "Unmarshal err:%s", err) | ||
return | ||
} | ||
glog.Infof(ctx, "res的长度:%d", len(res)) | ||
} |