Spring Social Facebook get album is giving 0 result - spring-social

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?

Related

Best Practice to Send Unique Booking QR Code to customers through e-mail in ASP.NET Core MVC

I'm developing a room booking website using ASP.NET Core MVC. The requirement is that every time when customer do the booking, the system will assign a unique booking Id and generate the QR Code for that Unique booking number and send an email with that QR Code (I'm using HTML Email Template). The customer will come to the staff and scan the QR Code for further process. I've generated the unique number, created a QR Code but failed to send this Code in Email. I'm able to send that QR code from my controller to view, but When I attach that QR code, It does not show in the Email.
I've read some of the questions on Google, most of the people say that we have to save that generated QR Code in the Server directory and then send its reference in the email. But I was wondering that If I have a thousand bookings in a month, then my server has to have one thousand QR code images in a folder and later on every day the number of images will be getting increased.
I can save images on the server and send in an email, but I wanted to know what is the best practice to achieve this task because many companies are already using this functionality.
Any suggestions, guidance will be appreciated.
The Practice Code that works fine for generating QR Code
Controller Code:
Random r = new Random();
int number = r.Next(10, 100000);
using (MemoryStream ms = new MemoryStream())
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(number.ToString(), QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap bitMap = qrCode.GetGraphic(20))
{
bitMap.Save(ms, ImageFormat.Png);
ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
ViewBag.Number = number;
}
}
And the Testing View Code is
#if (ViewBag.QRCodeImage != null)
{
<h3>Booking Number is #ViewBag.Number</h3>
<img src="#ViewBag.QRCodeImage" alt="" style="height:150px;width:150px" />
}
Is is working fine and showing me the QR Code in my View
But When I'm sending this QR Code in Email it is not displaying in email.
Actual Code for Email in Controller:
string qrImagePath = "";
using (MemoryStream ms = new MemoryStream())
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(number.ToString(), QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap bitMap = qrCode.GetGraphic(20))
{
bitMap.Save(ms, ImageFormat.Png);
qrImagePath = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
ViewBag.Number = number;
}
}
MailText = MailText.Replace("[qrCode]", qrImagePath);
EmailHelper emailHelper = new EmailHelper();
bool emailResponse = emailHelper.SendEmail(model.Email, "Booking", MailText);
Email Helper is sending email and I can see the newly sent email in my inbox but QR Code Picture is not displaying.
QR Code Image is not displaying in Email and I cannot see the src attribute of an image in the email.
If anyone can guide me, I'll be very thankful.
Have a good day.

How to store profile image to SQL server using web API in Xamarin Forms

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);
}

Upload photos to Google Photos API - Error 500

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

Google Apps Script - get 'hosting' url for public image on Drive

and thanks in advance for your help!
I'm trying to get the 'hosting' URL for public images on my Google Drive, with the intent of pulling the images into a spreadsheet using the Image formula. Unfortunately, there doesn't seem to be a way to get the hosting URL from Google Apps Script.
The ID used in the hosting URL isn't the same as the ID of the file on Drive, either, so I can't figure out how to build the URL.
Is there a way to get this URL or ID so I can pull in these images to my spreadsheet?
Thanks again for any help you can provide.
Can the use of permalink be an option for you?
here an exemple:
var baseUrl = "http://drive.google.com/uc?export=view&id=";
function myFunction() {
var images = DriveApp.getFilesByType(MimeType.JPEG);
while(images.hasNext()){
var img = images.next();
// img.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW); this line can be dangerous!!
var imgId = img.getId();
var pubUrl = baseUrl+imgId; // the public URL
Logger.log(pubUrl);
}
}

How to retrieve video view counts from YouTube API

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");

Resources