kirannandedkar
asked on
Fetch images from instagram
I am extremely new to sharepoint. I wish to create daily job to fetch #tag images from instagram and load it in list
I have created daily job to add task to already created list like below. I have added this code in Execute method.
Now i think i need to use sharepoint server side api to connect to instagram api and fetch images and load in list.
How can i achieve this? I have googled a lot but no help available.
I have created daily job to add task to already created list like below. I have added this code in Execute method.
SPList thisTaskList = oSPWeb.Lists["MyTaskList"];
SPListItem tasks = thisTaskList.Items.Add();
tasks["Title"] = "New task" + DateTime.Now.ToString();;
tasks.Update();
Now i think i need to use sharepoint server side api to connect to instagram api and fetch images and load in list.
How can i achieve this? I have googled a lot but no help available.
ASKER
Hello may i know if there is anyone to help me here. I dont need full fledged solution here
Hi,
some questions upfront:
- Which SharePoint version and edition?
- What do you mean with "load image in list" ?
Do you want to create list entries with the image metadata OR upload images as attachment to a list item OR upload images to a document library?
- What do you mean with "#tag images"?
How many images do you expect to get per day (just to consider the sizing / proper list/library structuring)?
Thanks.
Rainer
some questions upfront:
- Which SharePoint version and edition?
- What do you mean with "load image in list" ?
Do you want to create list entries with the image metadata OR upload images as attachment to a list item OR upload images to a document library?
- What do you mean with "#tag images"?
How many images do you expect to get per day (just to consider the sizing / proper list/library structuring)?
Thanks.
Rainer
ASKER
I am using sharepoint 2013 . I meant load images in document library and then upload in list entries. #tag images are one which we search for particular tag in instagram and it gives images connected to that tag. I expect to get around 500 images per day. Please help me
ASKER
I have this code below which successfully gives me images. But i dont know how to save those in document library.
do
{
WebRequest webRequest = null;
if (webRequest == null && string.IsNullOrEmpty(nextPageUrl))
webRequest = HttpWebRequest.Create(String.Format("https://api.instagram.com/v1/tags/{0}/media/recent?access_token={1}", strtagName, strAccessToken));
else
webRequest = HttpWebRequest.Create(nextPageUrl);
var responseStream = webRequest.GetResponse().GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
using (StreamReader reader = new StreamReader(responseStream, encode))
{
JToken token = JObject.Parse(reader.ReadToEnd());
var pagination = token.SelectToken("pagination");
if (pagination != null && pagination.SelectToken("next_url") != null)
{
nextPageUrl = pagination.SelectToken("next_url").ToString();
}
else
{
nextPageUrl = null;
}
var images = token.SelectToken("data").ToArray();
foreach (var image in images)
{
imageUrl = image.SelectToken("images").SelectToken("standard_resolution").SelectToken("url").ToString();
if (String.IsNullOrEmpty(imageUrl))
Console.WriteLine("broken image URL");
var imageResponse = HttpWebRequest.Create(imageUrl).GetResponse().GetResponseStream();
var imageId = image.SelectToken("id");
object outputDir = null;
using (var imageWriter = new StreamWriter(String.Format("{0}\\{1}.jpg", outputDir, imageId)))
{
imageResponse.CopyTo(imageWriter.BaseStream);
imageResponse.Flush();
Console.WriteLine("copied {0}", imageId);
}
return imageUrl;
}
}
}
while (!String.IsNullOrEmpty(nextPageUrl));
You don't need to use SharePoint to grab the images. You should be able to download the images you want using something besides SharePoint. Once you have the images, you can use PowerShell to upload to what ever document library you want. No need to complicate grabbing images with SharePoint.
Hope that helps
Hope that helps
Hi
can you have a look on the link below to authenticate on instagram and have the images
http://www.c-sharpcorner.com/UploadFile/raj1979/how-to-authenticate-and-get-data-using-instagram-api/
code to add the images to SharePoint
String fileToUpload = @"C:\YourFile.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
String documentLibraryName = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(fi leToUpload ))
throw new FileNotFoundException("Fil e not found.", fileToUpload);
SPFolder myLibrary = oWeb.Folders[documentLibra ryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName (fileToUpl oad);
FileStream fileStream = File.OpenRead(fileToUpload );
// Upload document
SPFile spfile = myLibrary.Files.Add(fileNa me, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
can you have a look on the link below to authenticate on instagram and have the images
http://www.c-sharpcorner.com/UploadFile/raj1979/how-to-authenticate-and-get-data-using-instagram-api/
code to add the images to SharePoint
String fileToUpload = @"C:\YourFile.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
String documentLibraryName = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(fi
throw new FileNotFoundException("Fil
SPFolder myLibrary = oWeb.Folders[documentLibra
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName
FileStream fileStream = File.OpenRead(fileToUpload
// Upload document
SPFile spfile = myLibrary.Files.Add(fileNa
// Commit
myLibrary.Update();
}
}
ASKER
Hi @tapiweb
What to put in variable fileToUpload is my question. Because i dont store image in any folder. I get directly from instagram. Please check my code where i get data from instagram .
What to put in variable fileToUpload is my question. Because i dont store image in any folder. I get directly from instagram. Please check my code where i get data from instagram .
fileToUpload should be image url on you code, i suppose
ASKER
Will that make any sense? Because in my code i m already getting imageurl and writing to streamwriter. Can u tell exactly where?
hi
the way I understood is you are getting the images from instagram and you need to add the images to SharePoint picture library.
there a different Arguments you can use to add, on my above code the line that add image to the library is
SPFile spfile = myLibrary.Files.Add(String urloffile, stream file/ byte[] file, bool overwrite);
Note the myLibrary is a SharePoint picture library or document library not a list
the way I understood is you are getting the images from instagram and you need to add the images to SharePoint picture library.
there a different Arguments you can use to add, on my above code the line that add image to the library is
SPFile spfile = myLibrary.Files.Add(String
Note the myLibrary is a SharePoint picture library or document library not a list
ASKER
is it possible for you to combine mine and your answer and give me one complete answer? My code fetches images from instagram and your code uploads it to document library.
ASKER
Looks like you are not understanding what i am asking. In your code you pass hard coded file name from your c drive. I dont have any images stored. I am directly getting from instagram in form of stream. Now i want to upload that to document library. Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I use byte array and pass that while adding file to picture library
ASKER