Having problems with uploading photos to TwitPic using OAuth in Objective C on the iPhone

前端 未结 4 995
一个人的身影
一个人的身影 2021-02-04 23:15

I have been working on an iPhone app that has a feature of uploading photos to TwitPic. I have it working with basic authentication.

I am trying to get it working with

4条回答
  •  臣服心动
    2021-02-04 23:32

    Use GSTwitPicEngine: https://github.com/Gurpartap/GSTwitPicEngine

    Using GSTwitPicEngine:

    Initialize the engine with class or as needed:

    self.twitpicEngine = (GSTwitPicEngine *)[GSTwitPicEngine twitpicEngineWithDelegate:self];
    

    Find the authorization token and supply to twitpicEngine with:

    [twitpicEngine setAccessToken:token];
    

    Then to upload image and attach a text message along with it (does not post to twitter):

    [twitpicEngine uploadPicture:[UIImage imageNamed:@"mypic.png"]  withMessage:@"Hello world!"]; // This message is supplied back in success delegate call in request's userInfo.
    

    To upload image only:

    [twitpicEngine uploadPicture:uploadImageView.image];
    

    Upon end of request, one of the delegate methods is called with appropriate data and information.


    GSTwitPicEngineDelegate protocol specifies two delegate methods:

    - (void)twitpicDidFinishUpload:(NSDictionary *)response {
      NSLog(@"TwitPic finished uploading: %@", response);
    
      // [response objectForKey:@"parsedResponse"] gives an NSDictionary of the response one of the parsing libraries was available.
      // Otherwise, use [[response objectForKey:@"request"] objectForKey:@"responseString"] to parse yourself.
    
      if ([[[response objectForKey:@"request"] userInfo] objectForKey:@"message"] > 0 && [[response objectForKey:@"parsedResponse"] count] > 0) {
        // Uncomment to update status upon successful upload, using MGTwitterEngine's instance.
        // [twitterEngine sendUpdate:[NSString stringWithFormat:@"%@ %@", [[[response objectForKey:@"request"] userInfo] objectForKey:@"message"], [[response objectForKey:@"parsedResponse"] objectForKey:@"url"]]];
      }
    }
    

    and

    - (void)twitpicDidFailUpload:(NSDictionary *)error {
      NSLog(@"TwitPic failed to upload: %@", error);
    
      if ([[error objectForKey:@"request"] responseStatusCode] == 401) {
        // UIAlertViewQuick(@"Authentication failed", [error objectForKey:@"errorDescription"], @"OK");
      }
    }
    

    All set?

提交回复
热议问题