Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to upload image after authentication #28

Closed
ashishguru1986 opened this issue May 26, 2013 · 23 comments
Closed

Not able to upload image after authentication #28

ashishguru1986 opened this issue May 26, 2013 · 23 comments

Comments

@ashishguru1986
Copy link

[TMAPIClient sharedInstance].OAuthConsumerKey = k_TUMBLR_CONSM_KEY;

[TMAPIClient sharedInstance].OAuthConsumerSecret = k_TUMBLR_SECRET_KEY;

[[TMAPIClient sharedInstance] authenticate:@"myapp://tumblr-authorize" callback:^(NSError *error) {

if (error)

    NSLog(@"Authentication failed: %@ %@", error, [error description]);

else{

    NSLog(@"Authentication successful!");

    [[TMAPIClient sharedInstance] photo:@"Test"

                          filePathArray:@[[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]]

                       contentTypeArray:@[@"image/png"]

                          fileNameArray:@[@"Default.png"]

                             parameters:@{@"caption" : @"Caption"}

                               callback:^(id response, NSError *error) {

                                   if (error)

                                       NSLog(@"Error posting to Tumblr");

                                   else

                                       NSLog(@"Posted to Tumblr");

                               }];

}

}];

I am trying to post image after authentication, i am able to authenticate using above code but not able to post image after success full authentication. I am getting @"Error posting to Tumblr". I did some debugging and getting request callback JSON below:

(NSDictionary *) $1 = 0x0715df70 {
meta = {
msg = "Not Authorized";
status = 401;
};
response = (
);
}

Please guide me what i am missing ?

@Sevenloveit
Copy link

photo:@"Test" here you can fill you blog name
ex: my blog :http://.www.sevenloveit.tumblr.com
blog name : seventloveit

@ashishguru1986
Copy link
Author

But if i dont know the blog name then how can i directly post to tumblr so that i can see it under post section on my home page ?

@ashishguru1986
Copy link
Author

Even i created a blog at tumblr and passed the same in photo:@"My Test Blog" , i am getting "Error posting to Tumblr".

@irace
Copy link
Contributor

irace commented May 28, 2013

I am guessing that you are not passing the blog name correctly. "My Test Blog" is not a valid blog name, as blog names cannot have spaces in them.

This is an example of how to post a photo. As far as I can tell you are doing everything right except passing a blog name. You can get the user's list of blogs by making a userInfo request.

@ashishguru1986
Copy link
Author

yes i was not passing a valid blog name. My requirement is to post directly on user dashboard from the app. To achieve this i must pass a valid blog name as per api method. But suppose i want to post a photo on dashboard then but i need to do. Is there any method to create a blog so that after blog is created i can post the photo or any method to directly post image on user dashboard ? Hope you are getting my requirement !!!

@sankaet
Copy link

sankaet commented May 30, 2013

Mine still doesnt post

[[TMAPIClient sharedInstance] photo:@"sankaet" filePathArray:@[post[@"gif"]] contentTypeArray:@[@"image/gif"] parameters:@{@"caption" : [NSString stringWithFormat:@"test post by %@",post[@"user_fullname"]]} callback:^(id response, NSError *error) {
if (error)
NSLog(@"Error posting to Tumblr");
else
NSLog(@"Posted to Tumblr");
}];

The error is

Error Domain=Request failed Code=400 "The operation couldn’t be completed. (Request failed error 400.)"

response {
errors = (
"Error uploading photo."
);
}

I guess the problem might be error uploading a photo that isn't on the device itself. does it have to be?

@irace
Copy link
Contributor

irace commented May 30, 2013

My requirement is to post directly on user dashboard from the app

Sorry, I am not getting your requirement. The dashboard is not something that can be posted to. Blogs have posts and if you follow a blog, its posts show up on your dashboard. You always need to be posting to a blog name that the currently authenticated user owns.

I guess the problem might be error uploading a photo that isn't on the device itself. does it have to be?

Yes. The filePathArray must contain local files that your application can read off disk and upload to the API.

@sankaet
Copy link

sankaet commented May 30, 2013

would a Cached NSData work?

@irace
Copy link
Contributor

irace commented May 30, 2013

No, sorry. Only paths to files on disk for now.

@irace irace closed this as completed May 30, 2013
@sankaet
Copy link

sankaet commented May 30, 2013

I am trying to save the data on disk before I upload even that doesnt seem to work

  NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
   NSURL *fileURL = [documentsDirectoryURL URLByAppendingPathComponent:@"tumblr.gif"];


    [object writeToFile:[fileURL absoluteString] options:NSDataWritingAtomic error:nil];

    [[TMAPIClient sharedInstance] photo:@"sankaet" filePathArray:@[[fileURL absoluteString]] contentTypeArray:@[@"image/gif"] parameters:@{@"caption" : [NSString stringWithFormat:@"%@'s test post",post[@"user_fullname"]], @"link": post[@"shortened_link"]} callback:^(id response, NSError *error) {
            if (error)
                NSLog(@"Error posting to Tumblr %@ and response %@",error,response);
            else
                NSLog(@"Posted to Tumblr");
        }];

Am I doing something wrong?

@irace
Copy link
Contributor

irace commented May 30, 2013

There could be any number of things going wrong. Use an HTTP proxy to ensure you're actually sending image data across the wire. It could be that the GIF you're trying to post is too big (a common problem), feel free to use the image from this fully functioning photo posting example to rule out a problem with your particular GIF.

@sankaet
Copy link

sankaet commented May 30, 2013

I tried

 [[TMAPIClient sharedInstance] photo:@"sankaet" filePathArray:@[[[NSBundle mainBundle] pathForResource:@"userDefaultPicture" ofType:@"png"]] contentTypeArray:@[@"image/png"] parameters:@{@"caption" : [NSString stringWithFormat:@"%@'s post",post[@"user_fullname"]], @"link": post[@"shortened_link"]} callback:^(id response, NSError *error) {
            if (error)
                NSLog(@"Error posting to Tumblr %@ and response %@",error,response);
            else
                NSLog(@"Posted to Tumblr");
        }];

even then it gives me an error

Error posting to Tumblr Error Domain=Request failed Code=400 "The operation couldn’t be completed. (Request failed error 400.)" and response {
errors = (
"Error uploading photo."
);
}

and when I use my GIFs it gives me the following error

JXHTTPMultipartBody.m (78) ERROR: The operation couldn’t be completed. (Cocoa error 260.)
Error posting to Tumblr Error Domain=Request failed Code=400 "The operation couldn’t be completed. (Request failed error 400.)" and response {
errors = (
"Error uploading photo."
);
}

@irace
Copy link
Contributor

irace commented May 30, 2013

Did you read my last comment? Did you verify that you're actually sending multipart data up to the server using an HTTP proxy? Did you try using the image in the fully working example I linked to? Seriously look at the raw HTTP requests made by the sample program and yours, using the same image file, and see what the difference is. This isn't an SDK issue at this point, you're running into some problem with the API. I'm guessing it's because your file either A) doesn't exist or B) is too large, as I previously stated. I don't know what else to tell you.

@ashishguru1986
Copy link
Author

Hi irace, suppose i am a new user on Tumblr and not following any blog. So how i can post a image using Tumblr API for iOS ?

@irace
Copy link
Contributor

irace commented Jun 3, 2013

This is a general Tumblr question, and not really related to the Tumblr SDK. How many blogs a user is following has nothing do with posting. You post to your blog, not someone else's. Every user has at least one blog; their primary blog's name is the same as their username.

I'd suggest reading through our help documents to get a better understanding of how Tumblr works: http://www.tumblr.com/help

@sankaet
Copy link

sankaet commented Jun 5, 2013

"Did you verify that you're actually sending multipart data up to the server using an HTTP proxy?" I am not sure how to do that. I did try to run the PhotoPostExample, that works just fine. Then I used the same code and the same image in my app and its still giving me the same error. I am not sure why

@sankaet
Copy link

sankaet commented Jun 6, 2013

also, the text posts work just fine, but still it doesn't show which app the post was made by (as it usually shows in the right hand corner), am I missing something?

@irace
Copy link
Contributor

irace commented Jun 6, 2013

No, only a few select applications are currently whitelisted for attribution.

@abhayv
Copy link

abhayv commented Sep 25, 2013

Is the multipart method of posting photo still supported by the API. I could not get it to work. Finally, got it working by going down to the lower level method

    TMAPIClient *client = [TMAPIClient sharedInstance];
    NSDictionary *parameters = @{@"source": @"http://upload.wikimedia.org/wikipedia/en/d/d5/Snowcrash.jpg"};
    [client post:blog type:@"photo" parameters:parameters
        callback:^(id response, NSError *error) {
            if (error) {
                NSLog(@"Error posting to Tumblr");
            } else {
            }
        }];

@irace
Copy link
Contributor

irace commented Sep 25, 2013

It's still there, can I see a code sample that wasn't working?

@abhayv
Copy link

abhayv commented Sep 25, 2013

The following did not work for me. I double checked that the image does exist in the bundle and that I can post text postings with the same credentials.

  [[TMAPIClient sharedInstance] photo:blog
                          filePathArray:@[[[NSBundle mainBundle] pathForResource:@"blue" ofType:@"png"]]
                       contentTypeArray:@[@"image/png"]
                          fileNameArray:@[@"blue.png"]
                             parameters:@{@"caption" : @"Caption"}
                               callback:^(id response, NSError *error) {
                                   if (error)
                                       NSLog(@"Error posting to Tumblr");
                                   else
                                       NSLog(@"Posted to Tumblr");
                               }];

@will-districtnerds
Copy link

I too am having difficulty posting a photo using the Photo example project. The error message is not helpful at all. Given that it's an example project the onboarding should be cleaner than this.

@jayz5
Copy link

jayz5 commented Oct 21, 2013

Same issue here. I copied the blue.png into my project, successfully completed authentication, checked my blog name with userInfo, but still cannot get the picture posted.

Error Domain=Request failed Code=400 "The operation couldn’t be completed. (Request failed error 400.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants