2017-10-20 79 views
0

我从办公室365构建了一个简单的联系簿,列出了我公司的所有共享联系人。 我也在尝试使用Graph和EWS,但我无法弄清楚什么是错的。从PHP EWS office365获取所有公共文件夹/共享联系人

搜索Microsoft Graph explorer似乎没有机会看到我的“其他联系人” - >“所有联系人”文件夹。 我一直在尝试使用“/ me/contactFolders”端点和“/ people”端点。非他们给了我结果。

我还使用了一个php-ews库(该项目建立在Laravel上)通过Exchange访问文件夹,但没有运气。 使用this example,我只能列出我的联系人,没有任何机会看到其他文件夹或其他类型的联系人。

有没有人有任何提示newbbie?

在此先感谢。 编辑 这是一个用PHP-EWS库工作控制器

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use garethp\ews\ContactsAPI as ContactsAPI; 

use garethp\ews\API; 
use garethp\ews\API\Enumeration; 
use garethp\ews\API\Type; 
use garethp\ews\API\ExchangeWebServices; 
//use garethp\ews\API\ExchangeAutodiscover; 
//use garethp\ews\API\Exception\AutodiscoverFailed; 
class SharedContatctsController extends Controller 
{ 
    // 
    public function index() 
    { 
     # code... 

     $mail='[email protected]'; 
     $pwd='password'; 
     $version='Exchange2016'; 
     //$apiS = ExchangeAutodiscover::getAPI($mail, $pwd); 
     //$server=$apiS->getClient()->getServer(); 
     $server='mail.example.com; 
     $api = ContactsAPI::withUsernameAndPassword($server, $mail, $pwd); 
     $contacts = $api->getContacts(); 
     //return print($api->getFolderId()); 
     //If you want to get contacts within a folder 
     //$folder = $api->getFolderByDisplayName('Altri Contatti', 'contacts'); 
     //$contacts = $api->getContacts($folder->getFolderId()); 
     return view('shared',array('contacts'=>$contacts,'displayName'=>$contacts['displayName'])); 
    } 

} 

这是(相当有效)显示“BackupContacts”文件夹是在同一目录“接触”

控制器
<?php 

namespace App\Http\Controllers; 
use Microsoft\Graph\Graph; 
use Microsoft\Graph\Model; 
use App\Http\Controllers\Controller; 

class OutlookController extends Controller 
{ 
public function contacts() 
{ 
    if (session_status() == PHP_SESSION_NONE) { 
    session_start(); 
    } 

    $tokenCache = new \App\TokenStore\TokenCache; 

    $graph = new Graph(); 
    $graph->setAccessToken($tokenCache->getAccessToken()); 

    $user = $graph->createRequest('GET', '/me') 
       ->setReturnType(Model\User::class) 
       ->execute(); 

    $contactsQueryParams = array (
    // // Only return givenName, surname, and emailAddresses fields 
    //"\$select" => "displayName,scoredEmailAddresses", 
    // Sort by given name 
    //"\$orderby" => "givenName ASC", 
    // Return at most 10 results 
    "\$orderby"=>"displayName", 
    "\$top" => "1000" 
); 

    $getContactsUrl = '/me/contactFolders/{BackuPlderId-retrieved-with-Graph}/contacts/?'.http_build_query($contactsQueryParams); 
    $contacts = $graph->createRequest('GET', $getContactsUrl) 
        ->addHeaders(array ('X-AnchorMailbox' => $user->getMail())) 
        ->setReturnType(Model\Contact::class) 
        ->execute(); 

    return view('contacts', array(
    'username' => $user->getdisplayName(), 
    'usermail' => $user->getMail(), 
    'contacts' => $contacts 
)); 
} 
} 
+2

我们总是乐于帮助和支持新的编码器,但是您需要首先帮助自己。 : - )***在[**做更多研究**之后](https://meta.stackoverflow.com/q/261592/1011527)如果你有问题**发布你已经尝试** **清楚说明什么不工作**并提供[最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。阅读[如何问](http://stackoverflow.com/help/how-to-ask)一个很好的问题。请务必[参观](http://stackoverflow.com/tour)并阅读[this](https://meta.stackoverflow.com/q/347937/1011527)。 –

+0

对不起@JayBlanchard。只是编辑,使其更清晰。 – Biro

回答

0

/me/contacts将只返回当前用户的默认联系人文件夹中的联系人。同样,/me/contactFolders将只返回了当前用户的邮箱中的联系人文件夹(和一个空的结果,如果没有什么超出了他们的默认文件夹。

这里的关键是/me元素。这是currently authenticated user代名词所以,如果谁认证的用户是[email protected]/me/contacts/users/[email protected]/contacts将返回同样的结果。

当前不是从/v1.0 API集检索组织联系人(即存储在您的联系人GAL)的方法。有但是中的orgContact对象API即将支持。

相关问题