Skip to content

Latest commit

 

History

History
113 lines (84 loc) · 4.16 KB

README.md

File metadata and controls

113 lines (84 loc) · 4.16 KB

baiduads-sdk

该项目为百度商业API SDK的Java实现。 包含两个模块:

  • baiduads-sdk:手动开发的sdk部分
  • baiduads-sdk-auto: 自动生成的sdk部分

快速开始

环境要求

  1. Java 1.8+
  2. Maven 3.5+

源码构建

sh build.sh

maven使用

添加依赖:

<dependency>
  <groupId>com.baidu.dev2</groupId>
  <artifactId>baiduads-sdk</artifactId>
  <version>${version}</version>
</dependency>

最新版本Maven

使用方式

以api: /json/sms/service/AccountService/getAccountInfo 为例:

AccountSerivce接口文档

/**
 * 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);

    }
}

认证

申请权限

权限认证

API 示例

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