该项目为百度商业API SDK的Java实现。 包含两个模块:
- baiduads-sdk:手动开发的sdk部分
- baiduads-sdk-auto: 自动生成的sdk部分
- Java 1.8+
- Maven 3.5+
sh build.sh
添加依赖:
<dependency>
<groupId>com.baidu.dev2</groupId>
<artifactId>baiduads-sdk</artifactId>
<version>${version}</version>
</dependency>
以api: /json/sms/service/AccountService/getAccountInfo
为例:
/**
* API tests for AccountService
*/
public class AccountServiceTest {
private static String appId = "{appId}";
private static Long userId = 0L; // {userId}
private static String authCode = "{authCode}";
private static String secretKey = "{secretKey}";
/**
* @throws ApiException
* if the Api call fails
*/
@Test
public void getAccountInfoTest() throws ApiException {
// get accessToken
OAuthService oAuthService = new OAuthService();
GetAccessTokenRequest request = new GetAccessTokenRequest();
request.setAppId(appId);
request.setUserId(userId);
request.setAuthCode(authCode);
request.setSecretKey(secretKey);
GetAccessTokenResponse response = oAuthService.getAccessToken(request);
String accessToken = response.getData().getAccessToken();
// init service
AccountService accountService = new AccountService();
// init request header
ApiRequestHeader requestHeader = new ApiRequestHeader();
// set oauth info
requestHeader.setUserName("{userName}");
requestHeader.setAccessToken(accessToken);
// init request
ApiAccountQueryRequest queryRequest = new ApiAccountQueryRequest();
ArrayList<String> fields = new ArrayList<>();
fields.add("pictureOptimizeSegmentStatus");
fields.add("balance");
fields.add("userLevel");
queryRequest.setAccountFields(fields);
// init requster wrapper
GetAccountInfoRequestWrapper requestWrapper = new GetAccountInfoRequestWrapper();
requestWrapper.setHeader(requestHeader);
requestWrapper.setBody(queryRequest);
GetAccountInfoResponseWrapper responseWrapper = accountService.getAccountInfo(requestWrapper);
Assert.assertTrue(responseWrapper.getHeader().getStatus() == 0);
}
}
Class | Method | HTTP request | Description |
---|---|---|---|
CampaignFeedService | addCampaignFeed | POST /json/feed/v1/CampaignFeedService/addCampaignFeed | |
CampaignFeedService | deleteCampaignFeed | POST /json/feed/v1/CampaignFeedService/deleteCampaignFeed | |
CampaignFeedService | getCampaignFeed | POST /json/feed/v1/CampaignFeedService/getCampaignFeed | |
CampaignFeedService | updateCampaignFeed | POST /json/feed/v1/CampaignFeedService/updateCampaignFeed |
百度如流讨论群:5995216