facebook 营销api集成
facebook 营销api集成
营销api需要通过后端服务器与facebook服务器交互
1、下载营销api java代码
git clone https://github.com/facebook/facebook-java-business-sdk.git
编辑器:IDEA
1 | // 在pom.xml中添加依赖 |
添加java文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import com.facebook.ads.sdk.APIContext;
import com.facebook.ads.sdk.AdAccount;
import com.facebook.ads.sdk.Campaign;
import com.facebook.ads.sdk.APIException;
public class QuickStartExample {
public static final String ACCESS_TOKEN = "[Your access token]";//Your access token
public static final Long ACCOUNT_ID = 123456789L; //Your account ID
public static final String APP_SECRET = "[Your app secret]";//Your app secret
public static final APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET);
public static void main(String[] args) {
try {
System.out.println("==========");
AdAccount account = new AdAccount(ACCOUNT_ID, context);
Campaign campaign = account.createCampaign()
.setName("Java SDK Test Campaign")
.setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS)
.setSpendCap(10000L)
.setStatus(Campaign.EnumStatus.VALUE_PAUSED)
.execute();
System.out.println(campaign.fetch());
} catch (APIException e) {
e.printStackTrace();
}
}
}
or
1 |
|
执行java文件既可发布请求到facebook服务器,
需要安全上网
1、主页推广
根据提示一步一步提交,到 沙盒账号,如果之前没有添加则新建,要推广的主页,如果无则新建
到下载示例代码,点下载,将会获得一个java文件,里面含有accessToken、appid、ad_account_id、app_secret等信息,
将该下载的SAMPLE_CODE.java文件放于与上面两个java文件同级目录,直接运行该java文件即可,
注意此时电脑需要科学上网,不然会报错Timeout