I have an app that I used to be able to sign into google account and then upload a video to that account. However the apps bundle ID changed and I had to update to googleSignIn.
So now when I open the view controller I want to upload the video from I have a google Sign In button which the user taps and signs in and choose to let the app have access to scopes:
googleapis.com/auth/youtube
googleapis.com/auth/youtube.upload
googleapis.com/auth/youtubepartner
googleapis.com/auth/youtube.force-ssl
I also update the apps developers key
So I now have a developers Key and a client id that I replaced from the old ones in the app for the following code
- (GTMOAuth2Authentication *)authForDailyMotion {
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];
NSString *redirectURI = #"http://www.google.com/OAuthCallback";
NSString *clientID = #"552XXXXXXXX3-banchtj9877k4o4noj32eu1h5jokctu0.apps.googleusercontent.com";
NSString *clientSecret = devKey;
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:#"my little world"
tokenURL:url
redirectURI:redirectURI
clientID:clientID
clientSecret:clientSecret];
return auth;
}
After the user signs in to google they are taken to a page that shows the access the app is requesting access to
manage the youtube account
view and manage assets and associated content on Youtube
manage youtube videos
When the user currently taps the "allow" button they are taken to google.com where they can upload the video and other things from the camera roll on the device.
I want the user to be redirected back to a view within the app where the viewer can
put in a title, description, tags, choose a category, and choose its privacy and then publish the video directly from the app using
- (void)uploadVideoFile {
NSString *audioName = [pictureDictionary4 objectForKey:#"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:#"/Movie"];
//Get a full path to the image in the documents directory.
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
GDataServiceGoogleYouTube *service = [self youTubeService];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];
NSString *filename = audioName;
NSData *data = [NSData dataWithContentsOfFile:fullPatha];
GDataYouTubeMediaGroup *media = [GDataYouTubeMediaGroup mediaGroup];
[media setMediaTitle:title];
[media setMediaDescription:desc];
[media addMediaCategory:category];
[media setMediaKeywords:keywords];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fullPatha
defaultMIMEType:#"video/mp4"];
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:media
/*fileHandle:fileHandle*/
data:data
MIMEType:mimeType
slug:filename];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:#selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
GTMHTTPUploadFetcher *uploadFetcher = (GTMHTTPUploadFetcher *)[ticket objectFetcher];
[uploadFetcher setLocationChangeBlock:^(NSURL *url) {
[self setUploadLocationURL:url];
by tapping "publish"
I think the redirect url needs to be changed so the authentication is given to the app and then used to upload the video. However I am not sure about this
Now if the user taps the done button and goes back to the app and puts in the information described above and taps "publish"
I get the following error.
upload failed: Error Domain=com.google.HTTPStatusCode=401 *(User authentacation required)
I think this is because the authorization is only given to do the upload on line and not through the app.
Can someone tell me if I am correct in this assumption and is so how can I redirect the user back to the app to upload the video after tapping "allow"
and if I am incorrect in my assumption can someone give me some guidance on how to make this work as I want, please.
Follow this steps to get GoogleSignIn.
Here is API to upload a video to YouTube.
Related
I am working on an app where I need to upload videos to server.Now here I have 2 things:
Shoot video using UIImagePickerController,generate a thumbnail and then upload to server
Pick video from Photos gallery, generate thumbnail and then upload to server.
Now the only difference between the two is:
When I use 'generateImageAsynchronouslyForTimes:completionHandler:' method,I get a call in its completionHandler block and I get an AVAsset.Now I am using below code to get its URL:
NSURL *path_url = [(AVURLAsset*)asset URL];
This is where I think things are getting messed up because I am getting something like this in case 2(when I pick video from gallery):
file:///var/mobile/Media/DCIM/102APPLE/IMG_2439.mp4
So I can't upload it while case 1 is is working fine.Is it something related to sandbox?
What's the difference between these 2 paths?
file:///private/var/mobile/Containers/Data/Application/DA4632E3-FA25-4EBE-9102-62495BF105BF/tmp/trim.07786CFE-2477-4146-9EA0-0A04042A8D05.MOV"
file:///var/mobile/Media/DCIM/102APPLE/IMG_2439.mp4
I guess its appSandbox path in 1)
In iOS, every app is like an island and there is a sandbox environment for it.So if you like to upload your video that is not in your sandbox,you will have to copy that video to your sandbox and then you can upload it.This is how you can do this:
NSURL *path_url = [(AVURLAsset*)asset URL];
PHAssetResource *asset_resource = [[PHAssetResource assetResourcesForAsset:[fetchResult lastObject]]firstObject];
PHAssetResourceRequestOptions *options = [PHAssetResourceRequestOptions new];
options.networkAccessAllowed = YES;
NSURL *newURL = [self getSandboxURLFromURL:path_url];
[[PHAssetResourceManager defaultManager] writeDataForAssetResource:asset_resource toFile:newURL options:options completionHandler:^(NSError * _Nullable error) {
//here you will get the newURL that you will use...
}];
//method to get sandbox URL
-(NSURL*)getSandboxURLFromURL:(NSURL*)photos_gallery_url{
NSString *last_path_component = [photos_gallery_url lastPathComponent];
NSString *pathToWrite = [NSTemporaryDirectory() stringByAppendingString:last_path_component];
NSURL *localpath = [NSURL fileURLWithPath:pathToWrite];
return localpath;
}
Summary (iOS 8, Xcode 6.4)
First question:- Can i share my app's Documents Directory's data with my other app?
If Yes, I've seen many questions related to this;
Move data/images between two iOS apps using custom URL handler,
http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629
But I found that these example only send text or URLs. Then I tried myself as below:
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://"];
NSURL* url = [NSURL URLWithString:path];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
The above code works well to open my other app. But when I try like below, I can't open my other app.
NSArray* mainPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourcePath = [mainPath objectAtIndex:0];
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://%#",sourcePath];
NSURL* url = [NSURL fileURLWithPath:path isDirectory:YES];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
So, please help me, what am I missing?
EDIT:-
i forgot to mention that,iOS7 support is important in my App.so, i think extension might not work.
Use NSUserDefaults with app group to share the data between apps
NSUserDefaults *defaults=[[NSUserDefaults
alloc]initWithSuiteName:#"app group name"];
[defaults setObject:filedata forKey:#"keyfordata"];
[defaults synchronize];
in the app delegate of consuming app fetch the data from NSUserDefaults
another way is to use share extension-
http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/
You can refer MGInstagram files as Instagram mobile app works same. You can pass image from your application to Instagram application.
You can download it from here: https://github.com/mglagola/MGInstagram
Hope this helps.
When I use UIDocumentInteractionController to allow users to share via Instagram, it does work, it brings up the option for "open with" and "Instagram" as one of the options... the problem is that it also displays many other apps like "Facebook" and "Twitter"...
Is there any way I can make it only give the option of opening in the instagram app?
Instagram claims there is a way to do this: http://instagram.com/developer/iphone-hooks/ but they mention this:
"Alternatively, if you want to show only Instagram in the application list (instead of Instagram plus any other public/jpeg-conforming apps) you can specify the extension class igo, which is of type com.instagram.exclusivegram."
but I honestly have no clue what this part means, "extension class igo"
My code:
UIImage *imageToUse = [UIImage imageNamed:#"imageToShare.png"];
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.ig"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
docController.delegate = self;
docController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:#"This is the users caption that will be displayed in Instagram"], #"InstagramCaption", nil];
docController.UTI = #"com.instagram.exclusivegram";
[docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES];
Turns out to get the doc controller to only open in Instagram you just save your png or jpg file in format ".igo" file type extension, (Maybe stands for Instagram-Only?)
Changed the third line of code in my code to read this instead:
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.igo"];
(With "igo")
and then it worked! :)
Lower version of iOS 13:
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.igo"];
After iOS 13:
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.ig"];
I am using my own dropbox account for uploading/downloading user's images in iOS app and therefore, don't want to show login screen to users (as I am using my own dropbox). But, getting error (code 401) while uploading/downloading files, even though I have app key, secret and access token as well.
If I do it by showing login screen (by linking a view controller), it works. But my requirement is to authenticate by access token.
Any help, would be very much appreciated..
Below is the piece of code:
DBSession *dbSession = [[DBSession alloc]
initWithAppKey:kAppKey
appSecret:kAppSecret
root:kDBRootDropbox]; // either kDBRootAppFolder or kDBRootDropbox
[dbSession updateAccessToken:kAppAccess accessTokenSecret:kAppSecret forUserId:#"<userid>"];
dbSession.delegate=self;
[DBSession setSharedSession:dbSession];
[DBRequest setNetworkRequestDelegate:self];
And while initiating DBRestClient:
_client = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
_client.delegate = self;
And upload functionality code:
NSString *filename = [self userProfileImagePath];
if (filename) {
NSString *localPath = [self imagePathForName:filename];
// Upload file to Dropbox
NSString *destDir = #"/";
[self.client uploadFile:filename toPath:destDir withParentRev:nil fromPath:localPath];
}
I have a app code that sends in request only when the app opens. However I need to have a continuos access to the file in the server which will be updated every second.
-(void)viewDidLoad
{
[super viewDidLoad];
NSURL *myurl = [NSURL URLWithString:#"URL"];
NSString *mystring = [NSString stringWithContentsOfURL:myurl encoding:NSASCIIStringEncoding error:nil];
//myTextView.text = realtime;
//NSLog(mystring);
NSString *stripped1 = [mystring stringByReplacingOccurrencesOfString:#"\r" withString:#""];
NSArray *rows = [stripped1 componentsSeparatedByString:#"\n"];
}
Is there a way that I can keep checking on my server file to load the data? Currently I can load it only once when I open the application. But its a live update application.
Thank you.
You may use apple notification to notify the user new data.
But I'm not sure if this is what you want.