![](/img/trans.png)
[英]Java - How to connect to Microsoft Office 365 SharePoint
[英]java to connect Microsoft dynamics 365
我需要使用Java連接Microsoft Dynamics 365 CRM,對於Java連接,我只能看到此( https://msdn.microsoft.com/zh-cn/library/jj602979(v=crm.5).aspx )鏈接。 誰能告訴我如何使用java連接ms動態。
我唯一需要的是將聯系人從CRM加載到我的應用程序中。
您應該使用WebAPI 。
Web API是Microsoft Dynamics 365(在線和本地)的新增功能,可提供可在多種編程語言,平台和設備上使用的開發體驗。 Web API實現了OData(開放數據協議)版本4.0,這是用於通過豐富數據源構建和使用RESTful API的OASIS標准。
通過鏈接: 連接和數據交換,Java與Microsoft Dynamics,您將獲得有關使用ADFS和OAuth2從Java與“ Dynamics”進行連接的詳盡教程。 所有細節都在那里。 本教程還實現了READ和WRITE操作。
該實現利用Java庫OLingo通過Dynamics應用程序的http端點交換實際的讀寫OData消息。
您可以使用我的GitHub示例 。 我使用adal4j來處理所有身份驗證開銷,它為我提供了一個承載令牌,可用於對組織進行api調用。
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.ClientCredential;
import okhttp3.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.lang.String;
import java.util.concurrent.Future;
public class Main {
public static void main(String[] args) {
String authority = "https://login.microsoftonline.com/";
String resource = "https://msott.crm.dynamics.com";
String clientId = "64f4cba8-0656-4ccd-8c2a-fd269fe7636f";
String clientSecret = "";
String tenantID = "grdegr.onmicrosoft.com";
ExecutorService service = Executors.newFixedThreadPool(1);
AuthenticationResult result;
try {
AuthenticationContext context = new AuthenticationContext(authority + tenantID, true, service);
Future<AuthenticationResult> future = context.acquireToken(resource, new ClientCredential(clientId, clientSecret), null);
result = future.get();
String accessToken = result.getAccessToken();
createWithDataReturned(accessToken);
}
catch (MalformedURLException e) { }
catch (InterruptedException e) { }
catch (ExecutionException e) { }
}
// TODO: 5
// Retrieving customized responses on POST method:
public static void createWithDataReturned(String accessToken) {
try {
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(mediaType, "{" +
"\"name\": \"Sample Postman Account\"," +
"\"creditonhold\": false," +
"\"address1_latitude\": 47.639583," +
"\"description\": \"This is the description of the sample account\"," +
"\"revenue\": 5000000," +
"\"accountcategorycode\": 1" +
"}");
Request request = new Request.Builder()
.url("https://msott.api.crm.dynamics.com/api/data/v9.0/accounts?$select=name,creditonhold,address1_latitude,description,revenue,accountcategorycode,createdon")
.post(body)
.addHeader("OData-MaxVersion", "4.0")
.addHeader("OData-Version", "4.0")
.addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader("Prefer", "return=representation")
.addHeader("Authorization", "Bearer " + accessToken)
.addHeader("cache-control", "no-cache")
.addHeader("Postman-Token", "472f1651-c4e1-47c1-8a5c-6f70636181b0")
.build();
Response response = client.newCall(request).execute();
String dataReturnedFromCreate = response.body().string();
System.out.println();
}
catch (IOException e) { }
}
}
我正在使用這些Maven軟件包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mrrobot</groupId>
<artifactId>dynamicscrmapi</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.