I am currently exploring the use of Google's YouTube API to retrieve view counts from YouTube channels.(Google.Apis.Youtube.v3.dll) . I can successfully retrieve information about videos in the channels but cannot retrieve actual viewcounts.
Example:
foreach (var channel in channelsListResponse.Items)
{
var viewcount = channel.Statistics.ViewCount;
I keep getting an "object reference not set to an instance of an object" error.
Does anyone have a .net code example retrieving view counts using the YouTube API or know what may be causing such an error?
Does this help you? It retrieves all info of a users profile https://developers.google.com/youtube/2.0/developers_guide_dotnet#Retrieving_a_User_Profile
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Samples.Helper;
using Google.Apis.Services;
using Google.Apis.Util;
using Google.Apis.Youtube.v3;
using Google.Apis.Youtube.v3.Data;
var youtube = new YoutubeService(new BaseClientService.Initializer()
{
Authenticator = auth
});
var viewcount = youtube.Videos.List("enter video ID here", "statistics");
Related
How to store profile image to SQL server using web API in Xamarin Forms, Here I will get image using xam.plugin.media, I am totally new using web api in xamarin forms, I have login page filed like firstname, lastname, id, profileimage,emailid, phonenumber, My Quesiton is, i want to store profile image and username,pwd,etc using web api(Post Method), Please give me any suggesstion to resolve this issue
For that you have to maeka one api call that save image as a string and convert string into bytes array I give example below.
FileData filedata = await CrossFilePicker.Current.PickFile();
if (filedata != null)
{
Data.Text = filedata.FileName;
byte[] a = filedata.DataArray;
string result = System.Text.Encoding.UTF8.GetString(filedata.DataArray);
//Your api call and save result value
EditorValue.Text = result;
System.Diagnostics.Debug.WriteLine(result);
}
I'm getting the error below while trying to upload media to Google Photos API, following the docs
This is how i retrieve my bytes array:
And this is how i make the request:
I've tried a lot of things and none of it work...
Note: I'm consuming other Google Photos API endpoints, such as Get Albums, Create Albums, Get Media and everything work as expected. The upload media is the only one i'm having trouble with.
Note 2: The token is being sent correctly.
Note 3: All the origin endpoints were configured in the google console (localhost included) so much so that other endpoints are working correctly.
Anyone can give me a light?
I am writing something similar in C# and was able to work with the photo api. My best advice is to double check headers. I hope this helps, additionally I added a postman screenshot of a successful call to the api:
public async Task<GoogleApiResponse> UploadPhoto(StorageFile photo)
{
var userInfo = UserInfoVault.GetUserInfo();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userInfo.AccessToken);
client.DefaultRequestHeaders.Add("X-Goog-Upload-File-Name", photo.DisplayName);
var fileStream = await photo.OpenAsync(FileAccessMode.Read);
var reader = new DataReader(fileStream.GetInputStreamAt(0));
await reader.LoadAsync((uint)fileStream.Size);
byte[] pixels = new byte[fileStream.Size];
reader.ReadBytes(pixels);
var httpContent = new ByteArrayContent(pixels);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
HttpResponseMessage photoResponse = client.PostAsync(ApiEdnpoints.UploadPhoto, httpContent).Result;
string strResponse = await photoResponse.Content.ReadAsStringAsync();
return null;
}
Postman screenshot of successful call to upload a photo
Is there a way to call PlacesServices' getDetails function from App Maker?
I have the Place ID from the Geocoder but I'd like to be able to get details about the place.
At this time there is no built-in Places service in Apps Script and you'll need to through these steps to make it work:
Go to Google Cloud Console
Create a brand new project or use the project associated with your App Maker deployment:
Using left navigation menu go to APIs & Services -> Dashboard
Click + Enable APIs and Services button
Search for Google Places API Web Service and enable it
Go to APIs & Services -> Credentials and create new API key if you don't have one
Back in App Maker! =) Create a server script:
var API_KEY = 'PUT_YOUR_API_KEY_HERE';
var PLACES_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=';
function getPlaceDetails_(placeId) {
var URL = PLACES_URL + placeId + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(URL);
var json = response.getContentText();
var placeDetails = JSON.parse(json);
return placeDetails;
}
This snippet is cornerstone for further scripting. You can use it with Calculated Model or just call it using google.script.run from client (note that for the second case you'll need to make this function public by removing underscore in the end of function name).
I am trying to do a reverse image search with the Google REST API with an image stored locally. I am using the new--not deprecated--REST API. I can do a text search and get results. I can not do a search with a local image. I can do a reverse image search on the image and get a result. Any suggestions?
My https string is:
https://www.googleapis.com/customsearch/v1?key=A******&cx=0****&q=file:///home/givonz/donald-trump-voicemail-feature.jpg
Also, tried this https string, which doesn't work either:
https://www.googleapis.com/customsearch/v1?key=A******&cx=0****&searchType=image&q=file:///home/givonz/donald-trump-voicemail-feature.jpg
This text string search works:
https://www.googleapis.com/customsearch/v1?key=A******&cx=0****&q=Some+String
It seems the service is deprecated and no longer available as an API and; it always needed a link (URL). There are a few services on the web that seem to provide the function. Bing, in spite of appearing to do so, doesn't seem to. Yahoo does a reverse image search, but, I couldn't find an API. "Incandescent" does provide this service and with an API.
This should work. Make sure you pass your key in the header.
var path = #"YOUR_IMAGE_PATH";
var url = "https://api.cognitive.microsoft.com/bing/v7.0/images/details?modules=similarimages";
using (var client = new HttpClient())
using (Stream imageFileStream = File.OpenRead(path))
{
var content = new MultipartFormDataContent();
var strContent = new StreamContent(imageFileStream);
strContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { FileName = "anynameworks" };
content.Add(strContent);
var message = await client.PostAsync(url, content);
return await message.Content.ReadAsStringAsync();
}
I want to get all the photos posted by user in facebook using spring social facebook.
I am able to get connected and able to retrieve user name and id, but when i am trying to retrieve album of photos, i am getting zero result . I tried using FQL operations and graph api.
following is my code which i am using for getting album.
PagedList<Album> albums = facebook.mediaOperations().getAlbums();
System.out.println(facebook.mediaOperations().toString());
System.out.println(facebook.GRAPH_API_URL);
// System.out.println(albums.size());
// List<Photo> images = new ArrayList<Photo>();
// for (Album album : albums) {
// images.addAll(facebook.mediaOperations().getPhotos(album.getId()));
// }
String query = "SELECT pid, src, src_small, src_big, caption FROM photo WHERE owner= me()";
List<Image> images = facebook.fqlOperations().query(query,
new FqlResultMapper<Image>() {
public Image mapObject(FqlResult result) {
Image image = new Image();
image.setPid(result.getString("pid"));
image.setSrc(result.getString("src"));
image.setSrc_small(result.getString("src_small"));
image.setSrc_big(result.getString("src_big"));
return image;
}
});
I tried something just now similar to the commented code you have and it worked fine for me. I ended up receiving all of the photos for the authorized user in all of that user's albums.
Is it possible that the user doesn't have "user_photos" permission? Or...maybe no albums/photos? Or possibly, the permissions for those albums and/or photos are set so that applications can't see them via the API?