I have a small gallery, it has two types of pictures, one is a preview, the other is a regular one, it opens when you click on the preview.
Here is this code, which is on line 173 of the controller:
$model = Gallery::getActive()->where(['code' => $code])->with(
[
'itemsPhoto' => static function (ActiveQuery $query) {
$query->with(['photo', 'preview']);
}
]
)->one();
So, I opened DB debug to look at the requests for this gallery, and I got this:
I have two pictures in my gallery right now. That is, for each picture there is a separate request (preview and regular).
How can I make requests for all pictures in the gallery not come separately, but all together, in one request, should this be done in the controller in this line or in another place?
I'm currently using the Graph API Explorer to make some tests. That's a good tool.
I want to get the user's friend list, with friends' names, ids and pictures. So I type :
https://graph.facebook.com/me/friends?fields=id,picture,name
But picture is only 50x50, and I would like a larger one in this request.
Is it possible ?
As described in this bug on Facebook, you can also request specific image sizes now via the new API "field expansion" syntax.
Like so:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
The best way to get all friends (who are using the App too, of course) with correct picture sizes is to use field expansion, either with one of the size tags (square, small, normal, large):
/me/friends?fields=picture.type(large)
(edit: this does not work anymore)
...or you can specify the width/height:
me/friends?fields=picture.width(100).height(100)
Btw, you can also write it like this:
me?fields=friends{picture.type(large)}
you do not need to pull 'picture' attribute though. there is much more convenient way, the only thing you need is userid, see example below;
https://graph.facebook.com/user_id/picture?type=large
p.s. type defines the size you want
plz keep in mind that using token with basic permissions, /me/friends will return list of friends only with id+name attributes
You can set the size of the picture in pixels, like this:
https://graph.facebook.com/v2.8/me?fields=id,name,picture.width(500).height(500)
In the similar manner, type parameter can be used
{user-id}/?fields=name,picture.type(large)
From the documentation
type
enum{small, normal, album, large, square}
Change the array of fields id,name,picture to id,name,picture.type(large)
https://graph.facebook.com/v2.8/me?fields=id,name,picture.type(large)&access_token=<the_token>
Result:
{
"id": "130716224073524",
"name": "Julian Mann",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15032818_133926070419206_3681208703790460208_n.jpg?oh=a288898d87420cdc7ed8db5602bbb520&oe=58CB5D16"
}
}
}
You can also try getting the image if you want it based on the height or width
https://graph.facebook.com/user_id/picture?height=
OR
https://graph.facebook.com/user_id/picture?width=
The values are by default in pixels you just need to provide the int value
I researched Graph API Explorer extensively and finally found full_picture
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture
P.S. I noticed that full_picture won't always provide full size image I want. 'attachments' does
https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture,attachments
Hum... I think I've found a solution.
In fact, in can just request
https://graph.facebook.com/me/friends?fields=id,name
According to http://developers.facebook.com/docs/reference/api/ (section "Pictures"), url of profile's photos can be built with the user id
For example, assuming user id is in $id :
"http://graph.facebook.com/$id/picture?type=square"
"http://graph.facebook.com/$id/picture?type=small"
"http://graph.facebook.com/$id/picture?type=normal"
"http://graph.facebook.com/$id/picture?type=large"
But it's not the final image URL, so if someone have a better solution, i would be glad to know :)
You can specify width & height in your request to Facebook graph API: http://graph.facebook.com/user_id/picture?width=500&height=500
You can size it as follows.
Use:
https://graph.facebook.com/USER_ID?fields=picture.type(large)
For details: https://developers.facebook.com/docs/graph-api/reference/user/picture/
From v2.7, /<picture-id>?fields=images will give you a list with different size of the images, the first element being the full size image.
I don't know of any solution for multiple images at once.
I got this error when I made a request with picture.type(full_picture):
"(#100) For field 'picture': type must be one of the following
values: small, normal, album, large, square"
When I make the request with picture.type(album) and picture.type(square), responses me with an image 50x50 pixel size.
When I make the request with picture.type(large), responses me with an image 200x200 pixel size.
When I make the request with picture.width(800), responses me with an image 477x477 pixel size.
with picture.width(250), responses 320x320.
with picture.width(50), responses 50x50.
with picture.width(100), responses 100x100.
with picture.width(150), responses 160x160.
I think that facebook gives the images which resized variously when the user first add that photo.
What I see here the API for requesting user Image does not support
resizing the image requested. It gives the nearest size of image, I think.
In pictures URL found in the Graph responses (the "http://photos-c.ak.fbcdn.net/" ones), just replace the default "_s.jpg" by "_n.jpg" (? normal size) or "_b.jpg" (? big size) or "_t.jpg" (thumbnail).
Hacakable URLs/REST API make the Web better.
rest-fb users (square image, bigger res.):
Connection myFriends = fbClient.fetchConnection("me/friends", User.class, Parameter.with("fields", "public_profile,email,first_name,last_name,gender,picture.width(100).height(100)"));
I think that as of now the only way to get large pictures of friends is to use FQL. First, you need to fetch a list of friends:
https://graph.facebook.com/me/friends
Then parse this list and extract all friends ids. When you have that, just execute the following FQL query:
SELECT id, url FROM profile_pic WHERE id IN (id1, id2) AND width=200 AND height=200
200 here is just an exemplary size, you can enter anything. You should get the following response:
{
"data": [
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
},
{
"id": ...,
"url": "https://fbcdn-profile-a.akamaihd.net/..."
}
]
}
With each url being the link to a 200x200px image.
I have the same problem but i tried this one to solve my problem. it returns large image.
It is not the perfect fix but you can try this one.
https://graph.facebook.com/v2.0/OBJECT_ID/picture?access_token=XXXXX
try to change the size of the image by changing the pixel size from the url in each json object as follows :
for example I change s480x480 to be s720x720
Before :
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/t1.0-9/q71/s480x480/10454308_773207849398282_283493808478577207_n.jpg
After :
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xfp1/t1.0-9/q71/s720x720/10454308_773207849398282_283493808478577207_n.jpg
JS styled variant.
Just set enormous large picture width and you will get the largest variant.
FB.api(
'/' + userId,
{fields: 'picture.width(2048)'},
function (response) {
if (response && !response.error) {
console.log(response.picture.data.url);
}
}
);
You can use full_picture instead of picture key to get full size image.
Note: From Graph API v8.0 you must provide the access token for every UserID request you do.
Hitting the graph API:
https://graph.facebook.com/<user_id>/picture?height=1000&access_token=<any_of_above_token>
With firebase:
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" +
loginResult.getAccessToken().getToken();
You get the token from registerCallback just like this
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
FirebaseUser user = mAuth.getCurrentUser();
String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" + loginResult.getAccessToken().getToken();
}
#Override
public void onCancel() {
Log.d("Fb on Login", "facebook:onCancel");
}
#Override
public void onError(FacebookException error) {
Log.e("Fb on Login", "facebook:onError", error);
}
});
This is what documentation says:
Beginning October 24, 2020, an access token will be required for all
UID-based queries. If you query a UID and thus must include a token:
use a User access token for Facebook Login authenticated requests
use a Page access token for page-scoped requests
use an App access token for server-side requests
use a Client access token for mobile or web client-side requests
We recommend that you only use a Client token if you are unable to use
one of the other token types.
I have a slider in the index page, which has 3 pictures and this pictures has links. What is the best way to change pictures and links: make db table sliders:
id
pic
link
and work with it, or make in config->settings.php something like this:
<?php
return [
'new_products_count' => 6,
'popular_products_count' => 6,
'paginate' => 20,
'admin_paginate' => 10,
'slider'=>[
1=>['img'=>'1.jpg','link'=>'www1'],
2=>['img'=>'2.jpg','link'=>'www2'],
3=>['img'=>'3.jpg','link'=>'www3']
]
];
and work with it like this:
Config::set('settings.slider[1]['img']=>'newimg.jpg')
Config::set('settings.slider[1]['link']=>'newWWW')
?
Would be safer to keep in the database for a couple of reasons.
1- If you cache your configuration, it may sometimes behave like a buggy application. I mean after changing an image and coming back, you may see the previous image displaying again. Because what you change at runtime is not persisted. Try to update a config option, e.g:
config(['database.connections.sqlite.driver' => 'fake']);
Then go check the file. tadaaa... the file didn't change.
2- You database is unlimited. YOu can add an infinite number of images (links) with much more options. Of course, you can also pass options to config() but using Eloquent or Query builder is more flexible.
I am having a small problem adding multiple dimensions to the API request for Search Console.
If I add the following to group by country it works fine.
$filters->setDimension("country");
$filters->setOperator("equals");
$filters->setExpression($country);
$filter->setFilters($filters);
$filter->setFilters(array($filters));
$request->setDimensionFilterGroups(array($filter));
But if I add another dimension below for device, it skips the country dimension and only runs the query with the device dimension. It's perfectly possible to run both according to this on the search console API site:
'filters': [{
'dimension': 'country',
'expression': 'ind'
}, {
'dimension': 'device',
'expression': 'MOBILE'
}]
So, any idea how I can use them both on a query?
It's probably simply some PHP code, but I can't find any documentation on multiple dimensions or any examples anywhere with PHP in mind.
It was simple.
$filters->setDimension("country");
$filters->setOperator("equals");
$filters->setExpression($country);
$filters2->setDimension("device");
$filters2->setOperator("equals");
$filters2->setExpression($device);
$filter->setFilters($filters);
$filter->setFilters(array($filters,$filters2));
$request->setDimensionFilterGroups(array($filter));
Works like a charm.
Many thanks for sharing this, Nick - it really helped!
One tiny thing: you won't need the following:
$filter->setFilters($filters);
as you're setting filters the right way with the next line of code.
Also, I was stuck on the following line:
$request->setDimensionFilterGroups(array($filter));
as I was passing the $filter object as it is instead of using an array.
I really found this counter-intuitive: this is the only object setDimensionFilterGroups method needs; I'm still wondering why it needs an array instead.
Cheers,
Sal
Nick's answer did helped me start but currently it isn't complete. To help other devs looking for an answer, hope this would help you:
$filter_group = new Google_Service_Webmasters_ApiDimensionFilterGroup;
$groups = array(['device', 'mobile', 'equals'], ['country', 'GBR', 'equals']);
$filters = array();
if($groups) {
foreach ($groups as $key => $group) {
$filters[$key] = new Google_Service_Webmasters_ApiDimensionFilter;
$filters[$key]->setDimension($group[0]);
$filters[$key]->setExpression($group[1]);
$filters[$key]->setOperator($group[2]);
}
$filter_group->setFilters($filters);
}
$request->setDimensionFilterGroups(array($filter_group));
Also take note, currently it won't work if in your filter group you have two or more same dimension but different value for filter or expression.
e.g.
$groups = array(['device', 'mobile', 'equals'], ['device', 'tablet', 'equals']);
It is because OR operation is currently not supported for filters.
Check here and this answer here.
According to Facebook's Graph API documentation (here), you can access various sizes of a user's profile picture through URLs such as:
https://graph.facebook.com/(userid)/picture?type=small
https://graph.facebook.com/(userid)/picture?type=large
You'll notice that the first resolves to a url ending in _t.jpg (the small thumbnail) and the second ending in _n.jpg (the large image). So far so good. Equivalently, we should be able to query for these images like this:
https://graph.facebook.com/(userid)?fields=picture&type=small
https://graph.facebook.com/(userid)?fields=picture&type=large
This latter format worked as expected for many months, until just a few days ago when it suddenly started ignoring the "type" parameter entirely - everything now resolves to an image ending in _q.jpg, which is the default if no "type" is specified. As a result, I can no longer figure out a way to query for the large image in PHP (my real problem). It used to work like this:
$pic = $facebook->api('/me', array('fields' => 'picture', 'type' => 'large'));
...but as described above, "type" has spontaneously started being ignored. I've spent several hours scouring their documentation but haven't been able to find any reference to what has changed, or the "new" way this should be done - any pointers would be hugely appreciated...
EDIT:
None of the following work, either (returns nothing):
$pic = $facebook->api('/me/picture', array('type' => 'large'));
$pic = $facebook->api('/(my_uid)/picture', array('type' => 'large'));
$pic = $facebook->api('/me/picture/?type=large');
$pic = $facebook->api('/(my_uid)/picture/?type=large');
Basically, since Facebook broke things a few days ago there doesn't seem to be any way to get a non-default picture size from PHP. You can try out some of the calls yourself from the Graph API Explorer (here).
Other related/relevant links:
http://stackoverflow.com/questions/2978761/facebook-graph-api-will-not-give-me-picture-data
http://stackoverflow.com/questions/7718704/requesting-picture-for-event
You must request the API with the field_expansion syntax
These api requests works :
$results = $facebook->api('/me', array('fields' => 'picture.height(300).width(300)'));
$results = $facebook->api('/me', array('fields' => 'picture.type(large)'));
As described in this bug on Facebook, you can request this via the new API "field expansion" syntax.
This works for me:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
I found a workaround - profile pictures of various sizes can still be accessed via an FQL query:
$pic = $facebook->api(array('method'=>'fql.query', 'query'=>"SELECT pic_big FROM user WHERE uid=$fb_uid"));
("pic_big" is equivalent to "type=large" - see here).
This still doesn't explain why the GRAPH call suddenly broke though, or why image sizes don't seem to be accessible via Graph at all anymore (which I'd still like to know)...but at least there's some way to get the other size photos.
Gotta love Facebook and their top-notch reliability...