I'm using the latest version of the Facebook PHP SDK (version 4). I finally figured out how to use it in my PHP code. Below is my code.
$user_profile = (new FacebookRequest($this->session, 'GET', '/me/?fields=id,first_name,last_name,picture,timezone,gender,link'))->execute()->getGraphObject(GraphUser::className());
$outputArray[$i]['first_name'] = $user_profile->getFirstName();
$outputArray[$i]['last_name'] = $user_profile->getLastName();
$outputArray[$i]['pictureURL'] = ;
What do i specify to receive the picture URL, i requested it?
Also, i manually opened up the fb php sdk file called GraphUser.php just to see if i can find the property myself. here it is on pastebin.
http://pastebin.com/K6Xg0MjN
As you can see, the GraphUser object doesn't contain any properties that deal with the picture, so where do i get the picture then?
please and thanks for reading
The isn't a field called picture for the user object. It's an edge:
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/picture
$picture_info = (new FacebookRequest($this->session, 'GET', '/me/picture'))->execute()->getGraphObject();
$outputArray[$i]['pictureURL']=$picture_info->getProperty('url');
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'm looking to get the user_location on login but it doesn't seem to work. I presumed the parameter in the graph was "locations" but it claims it's been deprecated as of 2.2. Are you not able to get user location anymore or is it because it's an array I need to do something extra? I can't seem to find the answer in the documentation. Thanks in advance.
My code:
$profile_request = $fb->get('/me?fields=first_name,last_name,email,gender');
$requestLikes = $fb->get('/me/likes?limit=20');
$requestlocation = $fb->get('/me/locations');
$profile = $profile_request->getGraphNode()->asArray();
$likes = $requestLikes->getGraphEdge();
$location = $requestlocation->getGraphNode()->asArray();
My error:
Graph returned an error: (#12) locations API is deprecated for versions v2.0 and higher
OK so I solved it. I don't know why but when I took "location" in with the array profile[] I was able to retrieve it. Not exactly sure why this works yet.
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).
I am trying to access my profile pic at a specified width & height, using PHP SDK via the following code:
$picture = $facebook->api('/me/picture', array('width'=>'160', 'height'=>'160'));
This gives a null array when dumped! But in GRAPH API Explorer, it was giving an array with the URL to the pic!
In API Explorer, this is what I used: /me/picture?width=160&height=160
Similarly, I tried to access just the picture, without passing any arguments. Same effect on that too!
Any idea on why it's happening so?
Thank you
Finally found it!
We have to add redirect=false parameter. Then only it would return the data!
Implementation using PHP SDK:
$picture = $facebook->api('/me/picture', array('width'=>'160', 'height'=>'160', 'redirect'=> 'false'));
I'm using Zend and PHP to upload and delete videos from my home page. The uploading part is working fine but to download is more complicated.
$videoEntryToDelete = $yt->getVideoEntry($videoId);
$yt->delete($videoEntryToDelete);
I use this code to delete a video and the first row do work. The video object is created and I can get all data from it. But when I try to delete it I get this error message:
"You must specify an URI to which to post"
Do anyone know how to solve this problem?
Thanks!
By default, getVideoEntry() gets a read only video object. In order to edit it, you must pass true in the third parameter for getVideoEntry(). The video object will then contain all of the metadata, including the URL required to delete it.
Try this:
$videoEntryToDelete = $yt->getVideoEntry($videoId, null, true);
$yt->delete($videoEntryToDelete);
there is also a method ready to use:
$videoEntryToDelete = $yt->getFullVideoEntry($videoId);
$yt->delete($videoEntryToDelete);