Youtube API v3 get comments - google-api

I am using Comments: list method
Request
https://www.googleapis.com/youtube/v3/comments?part=snippet&parentId=ay4MKe1u7Ec&key=`{MY_KEY}`
I use API get comments return this
{
"kind": "youtube#commentListResponse",
"etag": "\"xmg9xJZuZD438sF4hb-VcBBREXc/pGLBhpjR05yQoJV31WoAx2PEFVw\"",
"items": []
}

The comments->list method is only used when you need to get additional info about comments where you already know the comment ID ... or in the case of your URL, if you are trying to get more details about comments that are replies to a parentID. In other words, you can't put a videoID into the comments->list method.
What you want is the commentThreads->list endpoint:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=ay4MKe1u7Ec&key={YOUR_API_KEY}
That'll give you all the comments with their IDs ... you can take those IDs, then, and run them through the comments->list endpoint to get more granular info.

Related

Change Wrap Strategy in Google Sheets with Ruby

Is it possible to change Wrap Strategy programmatically? I've already tried with
batch_update_spreadsheet documentation
service.batch_update_spreadsheet
and
stackoverflow question
batch_update
but neither worked.
It always return Invalid Request.
My request, as I understand from here, is just
service.batch_update_spreadsheet([{ 'wrapStrategy': 'WRAP' }])
What am I doing wrong? I want to change all cells from my sheet.
Thanks
From service.batch_update_spreadsheet([{ 'wrapStrategy': 'WRAP' }]) and I want to change all cells from my sheet., I guessed that your goal is as follows.
You want to reflect 'wrapStrategy': 'WRAP' to a sheet in a Google Spreadsheet using googleapis for ruby.
You have already been able to get and put values to Google Spreadsheet with Sheets API.
In this case, how about the following sample script?
Sample script:
spreadsheet_id = '###' # Please set your Spreadsheet ID.
sheet_id = '###' # Please set your sheet ID.
request_body = {
requests: [{repeat_cell: {
range: {
sheet_id: sheet_id,
},
cell: {
user_entered_format: {
wrap_strategy: 'WRAP'
}
},
fields: 'userEnteredFormat.wrapStrategy'
}}]
}
service.batch_update_spreadsheet(spreadsheet_id, request_body, {})
When this script is run, the wrapStrategy of sheet_id is set as WRAP.
In this case, please use the snake case for the keys instead of the camel case. Please be careful about this.
Note:
In this sample script, it supposes that your client of service can be used for updating the spreadsheet. Please be careful about this.
References:
Method: spreadsheets.batchUpdate
RepeatCellRequest

How to retrieve only the number of seats for all the subscriptions of my customers? (Google Workplace Reseller)

I am using the following JS code to retrieve seats details for all the subscriptions of my customers.
gapi.client.reseller.subscriptions.list()
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
However, it's returning all of their other information as well. How can I customize it so that it only returns the number of seats?
Google APIs has a standard parameter called fields that allows you select which fields are included in the response (see documentation on Docs API).
In Google API Client Library for JavaScript (aka gapi) you can simply add the parameters in an object when making a request. In your case this should work:
gapi.client.reseller.subscriptions.list({
fields: [
'nextPageToken',
'subscriptions/subscriptionId',
'subscriptions/seats/numberOfSeats',
].join(',')
})
It's important to keep all fields that you need including control fields like nextPageToken. You can read more about the format used here.

Google Search Console - get property set name

I work with "Search Console API v3" now.
When I use "webmasters.sites.list" method, I get site URLs and propery sets. Propery set for expample - "sc-set:B9KPftMA4RltK1LS61GR2g".
But I can't find any way to get REAL NAME for property set using API.
I can't show this id "sc-set:B9KPftMA4RltK1LS61GR2g" to client instead normal name.
Example of response:
"siteEntry": [ { "siteUrl": "example.com", "permissionLevel": "siteRestrictedUser" },
{ "siteUrl": "sc-set:2d0rU0BQiIHsmCH-HGZ1KA", "permissionLevel": "siteRestrictedUser" }
]
when you call sites.list it returns a list of site resources which contain
{
"siteUrl": "http://www.daimto.com/",
"permissionLevel": "siteOwner"
},
There is no way to get any additional information about the site than that. What i am not able to understand is why you appear to be getting back some kind of id.

Getting Google+ profile picture url with user_id

I know that lots of social network APIs provide a way to construct a url to the profile picture of a user, using their user_id or username. For Facebook it looks like this:
http://graph.facebook.com/user_id/picture?type=square
Now is there something like this for Google Plus? Or any other way to get user's pic without an API call??
Google had changed their policy so the old way for getting the Google profile image will not work now, which was
https://plus.google.com/s2/photos/profile/(user_id)?sz=150
New Way for doing this is
Request URL
https://www.googleapis.com/plus/v1/people/115950284...320?fields=image&key={YOUR_API_KEY}
That will give the Google profile image url in json format as given below
Response :
{
"image":
{
"url": "https://lh3.googleusercontent.com/-OkM...AANA/ltpH4BFZ2as/photo.jpg?sz=50"
}
}
More parameters can be found to send with URL which you may need from here
For more detail you can also check the given question where I have answered for same type of problem
How to get user image through user id in Google plus?
UPDATE: The method below DOES NOT WORK since 2015
It is possible to get the profile picture, and you can even set the size of it:
https://plus.google.com/s2/photos/profile/<user_id>?sz=<your_desired_size>
Example: My profile picture, with size set to 100 pixels:
https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100
Usage with an image tag:
<img src="https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100" width="100" height="100">
Hope you get it working!
UPDATE: Google stopped support for this method, that now returns a 404 (not found) error.
All this urls fetch the profile picture of a user:
https://www.google.com/s2/photos/profile/{user_id}
https://plus.google.com/s2/photos/profile/{user_id}
https://profiles.google.com/s2/photos/profile/{user_id}
They redirect to the same image url you get from Google API, an ugly link as
lh6.googleusercontent.com/-x1W2-XNKA-A/AAAAAAAAAAI/AAAAAAAAAAA/ooSNulbLz8U/photo.jpg
The simplest is to directly use like image source:
<img src="https://www.google.com/s2/photos/profile/{user_id}">
Otherwise to obtain exactly the same url of a Google API call you can read image headers,
for example in PHP:
$headers = get_headers("https://www.google.com/s2/photos/profile/{user_id}", 1);
echo "<img src=$headers[Location]>";
as described in article Fetch Google Plus Profile Picture using PHP.
Approach 1: (no longer works)
https://plus.google.com/s2/photos/profile/<user_id>?sz=<your_desired_size>
Approach 2: (each request counts in your api rate limits which is 10k requests per day for free)
https://www.googleapis.com/plus/v1/people/<user_id>?fields=image&key={YOUR_API_KEY}
with the following response format:
{ "image": { "url": "lh5.googleusercontent.com/-keLR5zGxWOg/.../photo.jpg?sz=50"; } }
Approach 3: (donot require api key)
http://picasaweb.google.com/data/entry/api/user/<user_id>?alt=json
in the json response you get a property named "gphoto$thumbnail", which contains the profile picture url like the following:
http://lh6.ggpht.com/-btLsReiDeF0/AAAAAAAAAAI/AAAAAAAAAAA/GXBpycNk984/s64-c/filename.jpg
You may notice in the url the portion "s64-c" which means the image size to be 64, I've tried using other values like "s100-c" and they worked. Also if you remove the "s64-c" part and append the "?sz=100" parameter, that will also work as of now. Though this is not very good way of getting the profile picture of a gplus user, but the advantage is it do not require any api key.
Google, no API needed:
$data = file_get_contents('http://picasaweb.google.com/data/entry/api/user/<USER_ID>?alt=json');
$d = json_decode($data);
$avatar = $d->{'entry'}->{'gphoto$thumbnail'}->{'$t'};
// Outputs example: https://lh3.googleusercontent.com/-2N6fRg5OFbM/AAAAAAAAAAI/AAAAAAAAADE/2-RmpExH6iU/s64-c/photo.jpg
CHANGE: the 64 in "s64" for the size
If you want to show the profile picture for the currently logged in user, you do not even need to know the {user_id}. Simply using https://plus.google.com/s2/photos/profile/me will be enough.
2020 Solution
Please comment if no longer available.
In order to get profile URL from authenticated user.
GET https://people.googleapis.com/v1/people/[THE_USER_ID_OF_THE_AUTHENTICATED_USER]?personFields=photos&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Response:
{
"resourceName": "people/[THE_USER_ID_OF_THE_AUTHENTICATED_USER]",
"etag": "12345",
"photos": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "[THE_USER_ID_OF_THE_AUTHENTICATED_USER]"
}
},
"url": "https://lh3.googleusercontent.com/a-/blablabla=s100"
}
]
}
and the link can be used as:
<img src="https://lh3.googleusercontent.com/a-/blablabla=s100">
You can get the URL for the profile image using the people.get method of the Google+ API. That does require an extra round trip, but is the most reliable way to get the image.
You technically can also use the URL https://s2.googleusercontent.com/s2/photos/profile/{id}?sz={size} which will then redirect to the final URL. {id} is the Google user ID or one of the old Google Profiles usernames (they still exist for users who had them, but I don't think you can create new ones anymore). {size} is the desired size of the photo in pixels. I'm almost certain this is not a documented, supported feature, so I wouldn't rely on it for anything important as it may go away at anytime without notice. But for quick prototypes or small one-off applications, it may be sufficient.
trying to access the /s2/profile/photo url works for most users but not all.
The only full proof method is to use the Google+ API. You don't need user authentication to request public profile data so it's a rather simple method:
Get a Google+ API key on https://cloud.google.com/console
Make a simple GET request to: https://www.googleapis.com/plus/v1/people/+< username >?key=
Note the + before the username.
If you use user ids instead (the long string of digits), you don't need the +
you will get a very comprehensive JSON representation of the profile data which includes:
"image":{"url": "https://lh4.googleusercontent.com/..... the rest of the picture url...."}
If you use Flutter, then you can access it via people.googleapis.com endpoint, code uses google_sign_in library
import 'package:google_sign_in/google_sign_in.dart';
Future<String> getPhotoUrl(GoogleSignInAccount account, String userId) async {
// final authentication = await account.authentication;
final url = 'https://people.googleapis.com/v1/people/${userId}?personFields=photos';
final response = await http.get(
url,
headers: await account.authHeaders
);
final data = json.decode(response.body);
return data['photos'].first['url'];
}
You will get something like
{
resourceName: people/998812322529259873423,
etag: %EgQBAzcabcQBAgUH,
photos: [{metadata: {primary: true, source: {type: PROFILE, id: 107721622529987673423}},
url: https://lh3.googleusercontent.com/a-/abcdefmB2p1VWxLsNT9WSV0yqwuwo6o2Ba21sh_ra7CnrZ=s100}]
}
where url is an accessible image url.
Tried everything possible.. here is final piece of working code. Hope it helps someone who is looking for it.
<?
$url='https://www.googleapis.com/plus/v1/people/116599978027440206136?fields=image%2Furl&key=MY_API_KEY&fields=image';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$d = json_decode($response);
$avatar_url = $d->{'image'}->{'url'};
echo $avatar_url;
?>
Simple answer: No
You will have to query the person API and the take the profile image.url data to get the photo. AFAIK there is no default format for that url that contains the userID.

How use Facebook Graph API to list event invitations and declined events for user

I have been trying to get list of event invitations sent to user. I played around with Graph API explorer found from
https://developers.facebook.com/tools/explorer
I have tried calling https://graph.facebook.com/userid/events but it returns me only events user has responded to as 'attending' or 'unsure'.
Is it possible to get list of event invitations for user like displayed in Facebook event page.
Also I don't know how to list events user has responded as 'declined'.
Maybe I am missing proper permission but I doubt it since I gave all event related permissions to grap explorer and still got only 'attending' or 'unsure' RSVPt events.
You can also do a GET on /{userid}/events/not_replied. It seems that Users that have not Joined the event will not show up in the /{userid}/events lists and if you look at the docs there is a subtle note there about only listing events that the user has joined. The old rest API seems to keep them in one list.
You will need to HTTP Get the following from the Graph API:
fql?q=SELECT uid,eid,rsvp_status FROM event_member WHERE uid = me()
You can get back all three statuses from that call.
{
"data": [
{
"uid": "723020003",
"eid": "19935786340002",
"rsvp_status": "not_replied"
},
{
"uid": "723020003",
"eid": "234524000290351",
"rsvp_status": "attending"
},
{
"uid": "723020003",
"eid": "210091000081240",
"rsvp_status": "declined"
}
]
}

Resources