2016-10-17 2 views
0

Я пытаюсь интегрировать свое приложение с API-интерфейсом SendGrid documentation, используя их php library.Интеграция API Sendgrid с Symfony2

Я установил его с помощью композитору (composer.json)

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

создали сервис (services.yml):

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

Услуги:

<?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(); 
    } 
} 

я получаю следующее ошибка:

Notice: Undefined property: SendGrid::$client 

Я не могу заставить его работать и не знаю, что делать дальше.

Заранее спасибо

ответ

1

Ваш код и documentation имеет отношение к последней версии SendGrid PHP SDK. Вы должны установить последнюю версию, чтобы она работала.

composer require sendgrid/sendgrid ~5.1 
Смежные вопросы