Skip to content

Commit

Permalink
feat:三方抓数/liftoff
Browse files Browse the repository at this point in the history
  • Loading branch information
mao888 committed Feb 5, 2024
1 parent 07f6846 commit 3eda2ed
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
49 changes: 49 additions & 0 deletions project/业务/三方抓数/liftoff/4、get-campaigns.go
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))
}
53 changes: 53 additions & 0 deletions project/业务/三方抓数/liftoff/6、get-creatives.go
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))
}

0 comments on commit 3eda2ed

Please sign in to comment.