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'));
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 want to develop a PHP project for getting the content of an Instagram post (via the post URL). I mean, for example, the crawler getting this Url and returning :
#TBT Used to love carrying them both at once #twinmom #mycoconuts
#mylifeinmyhands #toobignow #istilltrysometimes #LOVE #forevermybabies
After I used the file_get_contents, the of returned response is empty. I don't know how to fix this problem. Can you help me?
I don't want to use the Instagram API!
You shouldn't use this since it will break as soon as Instagram makes a change to their markup, but here you go:
<?php
$instagram_url = "https://www.instagram.com/p/BX6IowXFbq9";
$source = file_get_contents($instagram_url);
preg_match('/<script type="text\/javascript">window\._sharedData =([^;]+);<\/script>/', $source, $matches);
$data = json_decode($matches[1]);
echo $data->entry_data->PostPage[0]->graphql->shortcode_media->edge_media_to_caption->edges[0]->node->text;
This is little late but I am able to fetch Instagram timeline, Specific Media Details.
E.g:
Fetch user's list of post
If Instagram User page url is https://www.instagram.com/marvel then to fetch this page data you can use below URL
https://www.instagram.com/marvel?__a=1
Fetch specific media post details
If Instagram post detail page url is https://www.instagram.com/p/BfeD8RxHwnC/?taken-by=marvel then to fetch this page data you can use below URL
https://www.instagram.com/p/BfeD8RxHwnC/?taken-by=marvel&__a=1
I just found out that Facebook updated their graph api and now require an access token to retrieve like counts for a page to be displayed on an external website. I went through the motions of setting up an app to get the token and have the following:
$fbData = json_decode(file_get_contents('https://graph.facebook.com/myFacebookName?access_toke=MyAppId|MySecretToken'));
print_r($fbData);
It seems to only be returning objects:
stdClass Object ( [name] => My Facebook Name [id] => id number )
And that is all, giving me nothing to parse through. The name and id coming through are correct so there is a connection happening. Note that I have edited out some information so MyFacebookName and MyAppId|MySecretToken are actually populated with the correct info. Any ideas how to get the full JSON list to grab page likes? Am I missing something?
UPDATE
Thanks to Tobi and further reading the graph api, documentation I was able to get the number of likes with with following:
$fbData = json_decode(file_get_contents('https://graph.facebook.com/name?fields=likes&access_token=appId|accessToken'));
<?php echo number_format($fbData->likes);?>
You need to specifically request the fields you want in the response. In your case this would be
https://graph.facebook.com/myFacebookName?fields=id,name,likes&access_toke=MyAppId|MySecretToken
I don't understand why you say there "nothing to parse", because the object IS returned and can be used. So what's the problem?
Using echo $fbData['likes'] should give you the number of likes.
See
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.4#fields
https://developers.facebook.com/docs/graph-api/reference/page#Reading
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');
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);