Microsoft Graph için GraphClient Nasıl Kullanılır

GraphClient ile Çalışma

Şunun bir örneği IGraphClient sınıfı, istekleri oluşturur, Microsoft Graph API’ye gönderir ve yanıtları işler.

ITokenProvider Nesnesi Oluştur

Yeni bir örnek oluşturmak için IGraphClient sınıfı, bir örnek sağlamanız gerekir: ITokenProvider, Microsoft Graph isteklerini kimlik doğrulayabilir.

ITokenProvider tokenProvider = new ITokenProvider() {
    Date expirationDate = null;

    @Override
    public void dispose() {
    }

    @Override
    public OAuthToken getAccessToken(boolean ignoreExistingToken) {
        // Gets oAuth access token.
        // If ignoreExistingToken is true, requests new token from a server. Otherwise behavior is depended on whether token exists or not.
        // If token exists and its expiration date is not expired returns current token, otherwise requests new token from a server.
        return null;
    }

    @Override
    public OAuthToken getAccessToken() {
        // Gets oAuth access token.
        // If token exists and its expiration date is not expired returns current token, otherwise requests new token from a server.
        return new OAuthToken("token", expirationDate);
    }
};

GraphClient Nesnesi Al

TokenProvider’ı ayarladıktan sonra bir şey almanız gerekir: IGraphClient nesnesi hizmete istek yapmak için. Bir tane aldıktan sonra IGraphClient kimlik doğrulaması yapılmış olduğunda, hizmete çağrılar yapmaya başlayabilirsiniz.

IGraphClient client = GraphClient.getClient(tokenProvider);

GCC High Uç Noktalarına Bağlanma

Bu IGraphClient GCC High uç noktalarına bağlanmayı setEndpoint yöntemi. Aşağıdaki kod örneği, klasörleri listelemek ve mesajları almak için istemcinin GCC High uç noktasına bağlanmasını nasıl yapılandıracağınızı gösterir:

client.setEndpoint("https://graph.microsoft.us");

GraphFolderInfoCollection folders = client.listFolders();

String folderId = null;
for (GraphFolderInfo folder : folders) {
    if ("Inbox".equals(folder.getDisplayName())) {
        folderId = folder.getItemId();
        break;
    }
}

GraphMessageInfoCollection messages = client.listMessages(folderId);
System.out.println("Messages in the Inbox: " + messages.size());

Microsoft Graph ile Klasörlerle Çalışma

Posta kutusu klasörlerinin listeleme, oluşturma, okuma, güncelleme, kopyalama, taşıma ve silme işlemleri aşağıda açıklanmıştır Microsoft Graph ile Klasörleri Yönetme.

Microsoft Graph Kullanarak Mesajları Listele

Mesajların listelemesi, alınması, sayfalama, oluşturma, güncelleme, gönderme, kopyalama, taşıma ve silinmesi, eklerinin yönetilmesi aşağıda açıklanmıştır Microsoft Graph ile Mesajları Yönetme.

Kategoriler API’si

Bkz. Outlook Kategorileriyle Nasıl Çalışılır.

Overrides API’si

Bkz. Geçersiz Kılmalarla Nasıl Çalışılır.

Kurallar API’si

Bkz. Outlook Kurallarıyla Nasıl Çalışılır.

Birden Çok Posta Kutusunu Desteklemek İçin Kaynak Kullanımı

Bkz. Birden Çok Mail Kutusuyla Çalışma - Mail Kutusu Bağlamını Değiştirme.

Defterler API

Microsoft Graph ile OneNote defterlerini yönetmek için Aspose.Email for Java aşağıdaki yöntemleri sunar IGraphClient:

  • createNotebook(GraphNotebook notebook)
  • copyNotebook(String notebookId, String groupId, String renameAs)
  • fetchNotebook(String notebookId)
  • listNotebooks() ve listNotebooks(ODataQueryBuilder query)
// Create a OneNote notebook
GraphNotebook newNotebook = new GraphNotebook();
newNotebook.setDisplayName("My Notebook");

GraphNotebook createdNotebook = client.createNotebook(newNotebook);

// Fetch a notebook
GraphNotebook fetchedNotebook = client.fetchNotebook(createdNotebook.getId());
System.out.println(fetchedNotebook.getDisplayName());

// List the notebooks
GraphNotebookCollection notebooks = client.listNotebooks();
for (GraphNotebook notebook : notebooks) {
    System.out.println(notebook.getDisplayName());
}