Esempio n. 1
0
 private function initFacebookApi($accessToken)
 {
     $fbApi = FacebookAds\Api::init(self::APP_ID, self::APP_SECRET, $accessToken);
     $fbApi->setLogger(new FacebookLoggerWrapper($this->get('logger')));
     $me = new AdUser('me');
     $adAccount = $me->getAdAccounts()->current();
     $adAccountId = $adAccount->getData()[AdFields::ACCOUNT_ID];
     $client = $this->createHttpClient();
     return new AdApi($adAccountId, self::PAGE_ID, $accessToken, $client);
 }
Esempio n. 2
0
 * Facebook.
 *
 * As with any software that integrates with the Facebook platform, your use
 * of this software is subject to the Facebook Developer Principles and
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
 * shall be included in all copies or substantial portions of the software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */
namespace FacebookAdsDocs;

use FacebookAds\Object\AdUser;
use FacebookAdsTest\Config\Config;
/** @var Config $config */
// _DOC open [ADUSER_GET_ADACCOUNTS]
// use FacebookAds\Object\AdUser;
$me = new AdUser('me');
$me->getAdAccounts();
// _DOC close [ADUSER_GET_ADACCOUNTS]
// _DOC open [ADUSER_GET_ADACCOUNTGROUPS]
// use FacebookAds\Object\AdUser;
$me = new AdUser('me');
$me->getAdAccountGroups();
// _DOC close [ADUSER_GET_ADACCOUNTGROUPS]
 /**
  * @param array $fields
  * @param array $params
  * @return Cursor
  */
 public function getAdUsers(array $fields = array(), array $params = array())
 {
     return $this->getManyByConnection(AdUser::className(), $fields, $params);
 }
define('SDK_DIR', __DIR__ . '/..');
// Path to the SDK directory
$loader = (include SDK_DIR . '/vendor/autoload.php');
// Configurations - End
if (is_null($access_token) || is_null($app_id) || is_null($app_secret)) {
    throw new \Exception('You must set your access token, app id and app secret before executing');
}
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use FacebookAds\Object\Fields\AdAccountFields;
use FacebookAds\Object\Fields\ConnectionObjectFields;
use FacebookAds\Object\Values\ConnectionObjectTypes;
Api::init($app_id, $app_secret, $access_token);
// Use the first account - Connection objects are not actually account-specific
// so the account ID doesn't matter
$user = new AdUser('me');
$accounts = $user->getAdAccounts([AdAccountFields::ID]);
$account = $accounts[0];
$connection_objects = $account->getConnectionObjects([ConnectionObjectFields::ID, ConnectionObjectFields::NAME, ConnectionObjectFields::OBJECT_STORE_URLS, ConnectionObjectFields::TYPE, ConnectionObjectFields::URL]);
// Group the connection objects based on type
$groups = [];
foreach ($connection_objects as $object) {
    if (!isset($groups[$object->type])) {
        $groups[$object->type] = [];
    }
    $groups[$object->type][] = $object;
}
foreach ($groups as $type => $type_objects) {
    $type_name = get_type_name($type);
    echo "\n", $type_name, "\n";
    echo str_repeat('=', strlen($type_name)), "\n";
<?php

// Add to header of your file
require_once __DIR__ . '/vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use FacebookAds\Logger\CurlLogger;
session_start();
$cwd = getcwd();
$conf = json_decode(file_get_contents("{$cwd}/conf/conf.json"), true);
$access_token = isset($_SESSION['facebook_access_token']) ? $_SESSION['facebook_access_token'] : $conf['access_token'];
print_r("<PRE>");
Api::init($conf['app_id'], $conf['app_secret'], $_SESSION['facebook_access_token']);
$me = new AdUser('me');
$my_adaccount = $me->getAdAccounts()->current();
print_r($my_adaccount->getData());
print_r("</PRE>");