2016-10-17 20 views
0

私のアプリをSendGrid API documentationphp libraryを使って統合しようとしています。Sendgrid APIとSymfony2の統合

私は作曲家(composer.json)サービス(services.yml)作成した

"require": { 
    ... 
    "sendgrid/sendgrid": "2.0.5", 
    "sendgrid/php-http-client": "3.4" 
} 

使用してそれをインストール:私は次の取得

<?php 

namespace AppBundle\Services; 

use SendGrid; 

class SendGridApiIntegration 
{ 
    private $api_key; 
    private $api_user; 

    public function __construct($api_user, $api_key) 
    { 
     $this->api_user = $api_user; 
     $this->api_key = $api_key; 
    } 


    public function testSendGrid() 
    { 
//  \SendGrid::register_autoloader(); 
//  $sg = new \SendGrid($this->api_user, $this->api_key); 
     $sg = new \SendGrid($this->api_key); 
     $request_body = json_decode('{ 
      "name": "pet", 
      "type": "text" 
     }'); 
     $response = $sg->client->contactdb()->custom_fields()->post($request_body); 
     echo $response->statusCode(); 
     echo $response->body(); 
     echo $response->headers(); 
    } 
} 

sendgrid_service: 
    class: AppBundle\Services\SendGridApiIntegration 
    arguments: ['%sendgrid_api_key%', '%sendgrid_api_user%'] 

がサービスをエラー:

Notice: Undefined property: SendGrid::$client 

私はそれを稼働させることができず、次に何をすべきか分かりません。

事前

答えて

1

あなたのコード内のおかげとdocumentationはSendGrid PHP SDKの最新バージョンに関連しています。最新バージョンをインストールして動作させる必要があります。

composer require sendgrid/sendgrid ~5.1