re sign java home_Java Docusign Authentication

I am trying to connect docusign using java. Below code I am using.

public class DocuSignExample1 {

private static final String Recipient = "xxx@gmail.com";

private static final String SignTest1File = "/src/test/docs/SignTest1.pdf";

private static final String BaseUrl = "https://demo.docusign.net/restapi";

private static final String IntegratorKey = "xxxxx";

private static final String UserId = "xxxxxx";

private static final String privateKeyFullPath = System.getProperty("user.dir") + "/src/test/keys/docusign_private_key2.txt";

public static void main(String[] args) {

System.out.println("nRequestASignatureTest:n" + "===========================================");

byte[] fileBytes = null;

try {

String currentDir = System.getProperty("user.dir");

Path path = Paths.get(currentDir + SignTest1File);

fileBytes = Files.readAllBytes(path);

} catch (IOException ioExcp) {

ioExcp.printStackTrace();

}

EnvelopeDefinition envDef = new EnvelopeDefinition();

envDef.setEmailSubject("Please Sign My Sample Document");

envDef.setEmailBlurb("Hello, Please Sign My Sample Document.");

// add a document to the envelope

Document doc = new Document();

String base64Doc = Base64.encodeToString(fileBytes, false);

doc.setDocumentBase64(base64Doc);

doc.setName("TestFile.pdf");

doc.setDocumentId("1");

List docs = new ArrayList();

docs.add(doc);

envDef.setDocuments(docs);

// Add a recipient to sign the document

Signer signer = new Signer();

signer.setEmail(Recipient);

signer.setName("Sanjay");

signer.setRecipientId("1");

// Above causes issue

envDef.setRecipients(new Recipients());

envDef.getRecipients().setSigners(new ArrayList());

envDef.getRecipients().getSigners().add(signer);

// send the envelope (otherwise it will be "created" in the Draft folder

envDef.setStatus("sent");

ApiClient apiClient = new ApiClient(BaseUrl);

try {

byte[] privateKeyBytes = null;

try {

privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));

} catch (IOException ioExcp) {

Assert.assertEquals(null, ioExcp);

}

if (privateKeyBytes == null)

return;

java.util.List scopes = new ArrayList();

scopes.add(OAuth.Scope_SIGNATURE);

OAuth.OAuthToken oAuthToken = apiClient.requestJWTUserToken(IntegratorKey, UserId, scopes, privateKeyBytes,

3600);

Assert.assertNotSame(null, oAuthToken);

// now that the API client has an OAuth token, let's use it in all

// DocuSign APIs

apiClient.setAccessToken(oAuthToken.getAccessToken(), oAuthToken.getExpiresIn());

UserInfo userInfo = apiClient.getUserInfo(oAuthToken.getAccessToken());

System.out.println("UserInfo: " + userInfo);

apiClient.setBasePath(userInfo.getAccounts().get(0).getBaseUri() + "/restapi");

Configuration.setDefaultApiClient(apiClient);

String accountId = userInfo.getAccounts().get(0).getAccountId();

EnvelopesApi envelopesApi = new EnvelopesApi();

EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);

System.out.println("EnvelopeSummary: " + envelopeSummary);

} catch (ApiException ex) {

ex.printStackTrace();

System.out.println("Exception: " + ex);

} catch (Exception e) {

e.printStackTrace();

System.out.println("Exception: " + e.getLocalizedMessage());

}

}

}

5888567f48e861f5f15cbacf8b78efe4.png

I am copying clientid and integratory key from given image.

Error : Error while requesting an access token: POST https://account-d.docusign.com/oauth/token returned a response status of 400 Bad Request

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值