I would like to create a campaign using Facebook API. I tried to run all available example without success.
First of all I created an App in order to have a APP_ID and a APP_SECRET.
I did all the procedure to add my Ad_account following the tutorial.
I downloaded all the SDK to facilitate Facebook API use like:
facebook-php-ads-sdk and run adgroup_creation.php and curl_log.php with my data, without success.
facebook-php-sdk-v4 I suppose it is less specific than the previous one.
Multi-Product Ads with the Facebook Marketing POST -> developers.facebook.com/ads/blog/post/2015/03/26/creating-multi-product-ads/
the developers reference -> developers.facebook.com/docs/reference/php/4.0.0
I used "Composer" to get all dependency.
In all this case I had problem to create a campaign using more or less this code:
$campaign = new \FacebookAds\Object\AdCampaign(null,"act_$ACCOUNT_ID");
$campaign->setData(array(
AdCampaignFields::NAME => 'My First Campaign',
AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS,
AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED ));
// PROBLEM is Here
$campaign->create();
Any help? How can I get a more useful error?
It's difficult to help without knowing the exact error. However, you could try this: before creating your campaign, initialize the API using:
Api::init(<your_app_id>, <your_ap_secret>, <your_token>);
(You need to load FacebookAds\Api to use this function).
Related
I'm using the PHP V2 API. I requested full access (scope: https://www.googleapis.com/auth/drive). I also tried adding all of the different scopes to no avail.
I'm fully able to retrieve all files and list them but the thumbnail link is always null. Same with 'hasThumbnail'.
I tried the API explorer on https://developers.google.com/drive/v2/reference/files/get#examples and it shows me the thumbnail links correctly.
The relevant code can be boiled down to this:
$drive = new Google_Service_Drive($this->client);;
$files = $drive->files->listFiles($parameters)->files;
This is the response from the API explorer.
The response from my code (for the same ID) is:
Found the solution. It took 5 hours to run into this such simple solution.
Not many fields show by default, you must specify which fields you want populated.
The modified basic query now is:
$this->drive->files->listFiles([
'fields' => 'nextPageToken, files(thumbnailLink, webViewLink)'
])->files;
I am using Facebook Ads SDK v2.6.0 and I would like to update the url_tags of an Ad.
$ad->creative['id'] contains the AdCreative's ID and is OK since read() returns actual data.
$creative = new AdCreative($ad->creative['id']);
$creativeData = $creative->read([
'link_url',
'name',
'object_story_spec',
'object_story_id',
'url_tags'
]); // $creativeData->url_tags is OK and contains tags we have now
$creative->setData(['url_tags' => "a=b&c=d"]);
$creative->update();
Then everything seems to work fine, the response is received and the result is {"success": true}.
No exceptions are thrown and everything goes smooth, but the url_params is updated neither in Facebook Ads Manager nor the field $creativeData->url_tags when I run the script again.
P.S. I was able to update the object_story_spec of AdCreative, but I would precisely since it wouldn't cause the ad to be re-approved.
Best regards, Alexander
It looks like url_tags are not one of the mutable fields of an AdCreative object, so you will have to re-create the creative with the new url_tags in order to achieve this.
The following section of the docs outlines which fields are mutable:
https://developers.facebook.com/docs/marketing-api/reference/ad-creative#Updating
Okay, so I'm using php to post soundcloud widgets on my website(no need to explain why and how because thath's not wath's important)
Here is my code:
if (strpos($post['link'], 'soundcloud.com') !== FALSE)
{
echo "<iframe width=\"500\" height=\"150\" scrolling=\"no\" frameborder=\"no\"
src=\"https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/".$trackID."&color=ff6600&auto_play=false&show_artwork=true\"></iframe>";
}
My variable $post['link'] outputs the soundcloud link in this form https://soundcloud.com/alex-oancea/best-thing-about-you-original
What I would like to do is get the track's id from the link and declare it as $trackID because as you can see in my code(in the src="" part), the widget uses the track's ID
I have looked into the soundcloud API and many other threads on this site but I didin't find how to do this or how to write the code...
Thanks in advance!
Check http://developers.soundcloud.com/docs#resolving
You can click the PHP button on the example and get a good way of getting a track ID:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID');
// a permalink to a track
$track_url = 'http://soundcloud.com/forss/voca-nomen-tuum';
// resolve track URL into track resource
$track = json_decode($client->get('resolve', array('url' => $track_url)));
Now $track->id is your track ID.
Just be aware you need the SoundCloud API for this, and you'll probably have to register your app with SoundCloud to use the service. I have not had personal experience with any of this so I can't provide any information about those processes.
If you experiment on your local machine (xampp in your case), you CANNOT make it work, beause the 'REDIRECT_URL' cannot be anything else but a valid link to a hosted domain. The API just does not accept (for the good reason) url's containing "localhost" or or "192.168.x.x"-style url's. This is simply because the API really sends info to the 'REDIRECT_URL' and it needs to be able to reach it.
You need to get in touch with your hosting provider and setup a "live" dev environement.
Assuming you are using the php-soundcloud from the mptre's Github:
Check https://developers.soundcloud.com/docs#resolving (and even the '/resolve' indicated in the 'see also' section).
You can get a good way of getting a track ID by this way:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// a permalink to a track
$track_url = 'http://soundcloud.com/forss/voca-nomen-tuum';
// resolve track URL into track resource
$track = json_decode($client->get('resolve', array('url' => $track_url), array(CURLOPT_FOLLOWLOCATION => true)));
// display all the information from that track resource
var_dump($track);
Now $track->id is your track ID.
?>
Just be aware you need the SoundCloud API for this, and you have to register your app with SoundCloud to use the service (Register your app).
Another information is that Webservers where a basedir restriction is set and/or safe mode is active don't allow the CURLOPT_FOLLOWLOCATION = true option. Here is a workaround for these webservers in the Soundcloud.php file.
I need a way to display videos from a specific channel on a page using PHP.
I have authenticated my app and I can use some methods using the advanced API. I am using the official vimeo PHP library to connect.
Below is what I am trying to do and when I dump the array I do not get anything. I can get info back from using get videos from the entire account method.
require_once('/url/vimeo/vimeo.php');
$vimeo = new phpVimeo('number', 'number');
$vimeo->setToken('number','numbers');
$videos = $vimeo->call('vimeo.channels.getVideos', array('ACCOUNT' => 'NAME'));
If I put the channel name where ACCOUNT is I will get an invalid signature error.
Is it worth using something like simple HTML parser for PHP and doing it that or worth sticking with the advanced API?
I would highly advise using the advanced api. If you parse the html, it will break any time vimeo changes their channel pages. Additionally, channels have more than one layout
eg: vimeohq and nicetype
The second parameter of the "call" function should be any querystring parameters the api method requires.
In the case of "vimeo.channels.getVideos" you can provide
channel_id
user_id
page
per_page
summary_response
full_response.
To experiment with the getVideos method, you can use the playground.
So in the end, I believe you want the function to look like this..
$videos = $vimeo->call('vimeo.channels.getVideos', array('channel_id' => 'NAME'));
where NAME is either the channel id, or the channel name (the channel name matches the url slug, so for example "nicetype" not "nice type"
I'm running in circle with this problem so I submit it here.
I have created a facebook fanpage and a website for my mother to promote her music. Since she is quite used to facebook I decided that instead of creating a whole backoffice, the website would simply display the fanpage's posts, photos and events. I do this with simple calls to
$data= $fb->api('/'.PAGE_ID.'/posts?fields=id');
for example (or 'notes', 'events'...). The problem is that I have to use a specific access token that I get from my own 'me/accounts/' permissions. From time to time (say every month) I have to go to the Graph API Explorer, get that token, and save it in the website config.
I'm wondering if I couldn't generate that access token server-side on my website, but I can't seem to make it happen. the facebook PHP SDK can't acces my api('/accounts') graph results unless I'm the authentified user (obviously), and a call to api(PAGE_ID.'?fields=access_token') only returns the page's ID.
What Am I doing wrong? can the facebook php sdk make api calls on my behalf (independently of users)?
More info : I created the fanpage, and a simple app called feed reader, with *manage_pages* permission. I'm the only user that authorized that app, and I don't want the user on the website to have to login (why should they? it's my fanpage, why would I need their *manage_page* permission?).
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
You can get to any users public posts like so:
Note: this assumes you are using the PHP SDK here http://developers.facebook.com/docs/reference/php/
$facebook = new Facebook(
array(
'appId' => 'fb_app_id',
'secret' => 'fb_secret',
)
);
$url = '/' . 'fb_username' . '/posts?fields=id,name,created_time,message,story,type&limit=10'; // you might need to screw with this some
$page = $facebook->api($url);
while(count($page['data']) > 0)
{
foreach($page['data'] as $fb_post)
{
// USE THEM DATAS
}
// Keep retrieving next pages until spent
$url_parts = parse_url($page['paging']['next']);
$url = '/' . 'fb_username' . '/posts?' . $url_parts['query'];
$page = $facebook->api($url);
}
this is an example from: https://github.com/fyaconiello/WP_Social_Network_Posts/ which pulls FB posts in and saves em as WP posts. It was written to answer a different question.