I am working with an iOS application in which i upload images on Picasa web albums from my iOS application.When i create album firstly i check whether any album with the same name exist or not so i fetch all the albums with their name and album id with the below code.
for (GDataEntryPhotoAlbum *albumEntry in feed)
{
NSString *title = [[albumEntry title] stringValue];
NSString *title1 = [albumEntry GPhotoID];
NSLog(#"File Title: %# | ID: %#",title,title1);
}
i get all the album name and albumid .
now i check with the current album name given by the user.
if ([title isEqual:albumName]){
//do not create new album
// return the album id
}
else{
//create new album
}
Everything working fine ,but now the problem is how can i send the albumid to the uploading method which is below mentioned:
- (void)_startUpload:(UIImage *)image:(NSString *)filePath{
NSLog(#"album feed is %#",albfeed);
// user/11106615845/albumid/6029121 gphotoID:60291215413
//GDataFeedPhotoAlbum *albumFeedOfPhotos = [self photoFeed];
//https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/114789383162963173862/albumid/6025392474120084449
//https://photos.googleapis.com/data/entry/user/1082642086705/albumid/60254095886065
NSURL *uploadURL1 = [[[albfeed uploadLink] URL] retain];
NSString *photoPath = [[NSBundle mainBundle] pathForResource:#"red_bull" ofType:#"jpg"];
NSString *photoName = [photoPath lastPathComponent];
NSLog(#"uploadURL1 : %#",uploadURL1 );
NSLog(#"photoPath : %#",photoPath);
NSLog(#"photoName : %#",photoName);
NSData *photoData = [NSData dataWithContentsOfFile:filePath];
if (photoData) {
GDataEntryPhoto *newEntry = [GDataEntryPhoto photoEntry];
[newEntry setTitleWithString:photoName];
[newEntry setPhotoDescriptionWithString:filePath];
[newEntry setTimestamp:[GDataPhotoTimestamp timestampWithDate:[NSDate date]]];
[newEntry setPhotoData:photoData];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:filePath
defaultMIMEType:#"image/jpeg"];
[newEntry setPhotoMIMEType:mimeType];
[newEntry setUploadSlug:photoName];
GDataServiceGooglePhotos *service = [self googlePhotosService];
SEL progressSel = #selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
service.authToken = authTokens;
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:newEntry
forFeedURL:uploadURL1
delegate:self
didFinishSelector:#selector(addPhotoTicket:finishedWithEntry:error:)];
[service setServiceUploadProgressSelector:nil];
}else {
NSLog(#"### Image not loaded");
}
i don't know how will i send the specific albumid so that i don't need to create a new album ,if that album is already found in my account.
How can i achieve that??
I don't want to create another album with the same name,,get the albumid and upload images on the previous album.
please help me out.
Thank you for your precious time.
Related
I am trying to using CoreSpotlight API in application , I have plist file which has a several items on it for example animals' name . So I need to set title string equal to on of those object , for example if users search Lion , the line name and for example its features appears on the spotlight . Here is my code :
- (void)setupCoreSpotlightSearch
{
CSSearchableItemAttributeSet *attibuteSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(__bridge NSString *)kUTTypeImage];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"animals" withExtension:#"plist"];
NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];
NSString *getNames = [NSString stringWithFormat:#"%#",playDictionariesArray];
NSLog(#"%#",getNames) ;
attibuteSet.title =getNames;
attibuteSet.contentDescription = #"blah blah ";
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:#"app name"
domainIdentifier:#"com.compont.appname"
attributeSet:attibuteSet];
if (item) {
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:#[item] completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"Search item indexed");
}
}];
}
}
The problem is getNames returns all names !!! how can I filter it when is user is searching an specific word from animals.plist
Thanks .
EDIT [Plist Image]:
You can maintain NSArray and iterate through playDictionariesArray, creating & initialising CSSearchableItem object with that particular entry in your data source.
- (void)setupCoreSpotlightSearch
{
NSURL *url = [[NSBundle mainBundle] URLForResource:#"animals" withExtension:#"plist"];
NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];
NSMutableArray * searchableItems = [[NSMutableArray alloc]init];
for(object in playDictionariesArray)
{
CSSearchableItemAttributeSet *attibuteSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(__bridge NSString *)kUTTypeImage];
attibuteSet.title =[NSString stringWithFormat:#"%#",object]; //retrive title from object and add here
//attibuteSet.contentDescription = #"blah blah "; // retrieve description from object and add here
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:#"app name"
domainIdentifier:#"com.compont.appname"
attributeSet:attibuteSet];
[searchableItems addObject:item];
}
if (searchableItems) {
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:searchableItems completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"Search item indexed");
}
}];
}
}
I haven't ran and tested the code.
you are not looping through each key. Use the code provided in this question.
CoreSpotlight indexing
Try it on a device that supports indexing.
NOT iPhone 4/4s or iPad.
I am having trouble getting the video url for a YouTube video. I can retrieve the playlist items with a thumbnail and title but I can't get the actual video url.
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.APIKey = #"API Key";
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"snippet,contentDetails"];
query.playlistId = #"playlist ID";
query.maxResults = 50;
GTLServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
// This callback block is run when the fetch completes
if (error == nil)
{
GTLYouTubeSearchListResponse *products = object;
for (GTLYouTubeSearchResult *item in products)
{
NSLog(#"%#", item.snippet);
NSString *dictionary = [item.snippet JSONValueForKey:#"videoId"];
GTLYouTubeThumbnailDetails *thumbnails = item.snippet.thumbnails;
GTLYouTubeThumbnail *thumbnail = thumbnails.high;
NSString *thumbnailString = thumbnail.url;
if (thumbnailString != nil)
{
[self.thumbnailsArray addObject:thumbnailString];
[self.thumbnailTitleArray addObject:item.snippet.title];
//[self.videos addObject:video];
NSLog(#"id: %#", dictionary);
}
}
}
else
{
NSLog(#"Error: %#", error.description);
}
[self.tableView reloadData];
}];
Does anyone know how to get the video url using the YouTube API?
First of all if you want only videos in your search result you should set type = video.
In your code:
query.playlistId = #"playlist ID";
query.maxResults = 50;
query.type = #"video";
You need to add "id" into part. Your query call will be:
GTLQueryYouTube *query = [GTLQueryYouTube queryForPlaylistItemsListWithPart:#"id,snippet,contentDetails"];
and in response you can get video id with id.videoId. So in your code it will be:
NSString *videoId = item.identifier.videoId;
Once you have the id, you can plug it in:
http://www.youtube.com/watch?v={VIDEO ID HERE}
The video resource in the v3 API does not provide a URL. What you can do instead is to append the video ID to a string. Play page URLs tend to be of the format:
http://www.youtube.com/watch?v={VIDEO ID HERE}
I want to get the ISRC code for Local itunes songs. I can get the metaData by the following codes:
MPMusicPlayerController *mp= mp = [MPMusicPlayerController applicationMusicPlayer];
NSURL *assetURL = [mp.nowPlayingItem valueForProperty:MPMediaItemPropertyAssetURL];
AVAsset *asset = [AVAsset assetWithURL:assetURL];
NSArray *metadata = [asset commonMetadata];
for ( AVMetadataItem* item in metadata ) {
NSString *key = [item commonKey];
NSString *value = [item stringValue];
NSLog(#"extra iptions %#",[item extraAttributes]);
NSLog(#"key = %#, value = %#", key, value);
NSLog(#"keyspace and Local %# %#",[item keySpace],[item key]);
}
But I am really wondering about how to get ISRC(International Standard Record Coding).
Try this (warning: typed into browser)
NSArray *metadata = [asset metadataForFormat:AVMetadataFormatID3Metadata];
if (metadata == nil) {
NSLog(#"No ID3 metadata for asset: %#", asset);
}
// From https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVFoundation_ID3Constants/Reference/reference.html
NSArray *filteredMetadata = [AVMetadataItem metadataItemsFromArray:metadata withKey:AVMetadataID3MetadataKeyInternationalStandardRecordingCode keySpace:nil];
AVMetadataItem *item = [filteredMetadata firstObject];
if (item != nil) {
NSLog(#"ISRC: %#", item.stringValue);
} else {
NSLog(#"No ISRC found for: %#", asset);
}
EDIT: I should mention, the reason your original code didn't print the value of the ISRC is because the ISRC is not part of the common metadata space, and won't be included in the array returned by [asset commonMetadata]. The ISRC key is specific to ID3 metadata, so if your asset does not have ID3 metadata associated with it, you will be unable to retrieve that information.
I'm trying to fetch iTunes library in ios.
And trying to retrieve top 10 playcount song in 5days.
Could you tell me how to do? Here's my code.
MPMediaPropertyPredicate is not right answer...I guess.
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSLog(#"Logging items from a generic query...");
NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *song in itemsFromGenericQuery) {
NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
NSString *artistName = [song valueForProperty:MPMediaItemPropertyArtist];
NSString *lastPlayeddate = [song valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *playCount = [song valueForProperty:MPMediaItemPropertyPlayCount];
NSLog (#"%#", songTitle);
text.text = [NSString stringWithFormat:#"%#\n%# %# %# %#", text.text, songTitle, artistName, lastPlayeddate, playCount];
}
All the best.
Apparently, play count is considered a "user defined" key, and therefore cannot be used in MPMediaPropertyPredicate
See http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMediaItem_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008211-CH1-SW38
You will have to iterate the songs and retrieve these properties manually.
enumerateValuesForProperties:usingBlock: is probably your most efficient option here.
http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMediaEntity_ClassReference/Reference/Reference.html#//apple_ref/occ/instm/MPMediaEntity/enumerateValuesForProperties:usingBlock:
I'm having an issue on uploading photo and tag user's friend to Facebook user's wall. It returns unknown error
If I removed the tags param, it will work perfect.
This is the code I use to post photo and tag users
NSMutableArray *chunks = [[NSMutableArray alloc] init];
NSMutableDictionary *tagDict=[[NSMutableDictionary alloc]init];
for(int i=0; i < appDelegate.listFriend.count ;i++) {
NSDictionary *friend = [appDelegate.listFriend objectAtIndex:i];
NSString *type = [NSString stringWithFormat:#"%#",[friend objectForKey:#"type"]];
if([type intValue] == 1) {
[tagDict setValue:[friend objectForKey:#"id"] forKey:#"tag_uid"];
[chunks addObject:tagDict];
}
}
[photoParams setObject:[chunks JSONString] forKey:#"tags"];
//test posting facebook's image's url
NSString *imagePath = urlPhoto;
NSURL *imageUrl = [NSURL URLWithString:imagePath];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
NSMutableDictionary *photoParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message", imageData, #"source", nil];
[appDelegate.facebook requestWithGraphPath:#"/me/photos" andParams:photoParams andHttpMethod:#"POST" andDelegate:appDelegate.self];
Please help me to resolve that issue, All ideas are appreciated.
Thanks
Check this Link from the facebook developer account. It worked well for me try yourself first if you want i can give the codes tooo.
FaceBook Docs Here