2016-10-17 4 views
0

내 앱을 SendGrid API documentationphp library을 사용하여 통합하려고합니다.Sendgrid API와 Symfony2의 통합

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

내가 할

나는 작곡가에게 서비스 (services.yml)를 작성 (composer.json)

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

를 사용하여 설치 오류 :

Notice: Undefined property: SendGrid::$client 

나는 그것을 작동시킬 수 없으며 다음에 무엇을해야할지 모른다.

사전

답변

1

코드에 감사하고 documentation는 SendGrid PHP SDK의 최신 버전으로 관련이있다. 제대로 작동하려면 최신 버전을 설치해야합니다.

composer require sendgrid/sendgrid ~5.1