2016-10-17 5 views
0

Ich versuche, meine App mit SendGrid API documentation unter Verwendung ihrer php library zu integrieren.Sendgrid-API-Integration mit Symfony2

Ich installierte es Composer (composer.json)

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

einen Dienst (services.yml) Erstellt:

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

Service:

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

ich die folgende Fehler:

Notice: Undefined property: SendGrid::$client 

Ich kann es nicht funktionieren und weiß nicht, was ich als nächstes tun soll.

Vielen Dank im Voraus

Antwort

1

Ihr Code und die documentation ist auf die neueste Version von SendGrid PHP SDK relevant. Sie sollten die neueste Version installieren, damit es funktioniert.

composer require sendgrid/sendgrid ~5.1