shyambhat / InstagramKit

The unofficial Instagram iOS SDK
MIT License
970 stars 265 forks source link

Relationship Endpoints #14

Closed shyambhat closed 10 years ago

shyambhat commented 10 years ago

http://instagram.com/developer/endpoints/relationships/

To contribute, please fork the branch 'relationships'

nickthedude commented 10 years ago

im trying to write this but im having a hell of a time getting the methods working and im not sure what im bumping up against. more specifically im trying to follow a user via a post command. i added the relationships permission, ive written this method:

- (void)followUser:(InstagramUser*)user
   withSuccess:(void (^)(void))success
       failure:(void (^)(NSError* error))failure
{
    NSDictionary *params = [NSDictionary dictionaryWithObjects:@[@"action=follow"] forKeys:@[kText]];
    [self postPath:[NSString stringWithFormat:@"users/%@/relationships",user.Id] parameters:params     responseModel:nil success:^{
        success();
    } failure:^(NSError *error, NSInteger statusCode) {
        failure(error);
        NSLog(@"%@", [error description]);
    }];
}

I've been able to get it to work on the api console on the instagram dev website but im not understanding this. are you sure the post works for comments even after the persission is granted via email request?

nickthedude commented 10 years ago

this is what i get:

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0xa949650 {NSErrorFailingURLKey=https://api.instagram.com/v1/users/602138059/relationships, NSLocalizedDescription=Request failed: not found (404), NSUnderlyingError=0xa96eb40 "Request failed: unacceptable content-type: text/html", AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xa941e80> { URL: https://api.instagram.com/v1/users/602138059/relationships }     { status code: 404, headers {
"Cache-Control" = "private, no-cache, no-store, must-revalidate";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Language" = en;
"Content-Type" = "text/html";
Date = "Fri, 28 Mar 2014 20:34:27 GMT";
Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
Pragma = "no-cache";
Server = nginx;
"Transfer-Encoding" = Identity;
Vary = "Accept-Language, Cookie";
"X-Frame-Options" = SAMEORIGIN;
} }}
shyambhat commented 10 years ago

I've not tested posting comments, but the post call does work in case of Likes.

I did face issues constructing the html body for the post requests. As it turned out, I was trying to set the Request Serializer to AFJSONRequestSerializer.

    self.operationManager.requestSerializer = [[AFJSONRequestSerializer alloc] init];

This caused it to create an json request body, whereas this property should have just been left alone to the default.

Please make sure you're NOT altering the default requestSerializer property.

shyambhat commented 10 years ago

Please fork this repo and commit your code into your fork. I can get it up and running and merge it with the main repo.

nickthedude commented 10 years ago

hey im not great with git, but i think i sent the right thing as a pull request. let me know i can try again.

shyambhat commented 10 years ago

Also, a lot of code has changed in the past couple of hours. Drastic changes to the Engine signatures to incorporate paging. Please use the latest code on master.

nickthedude commented 10 years ago

yes i agree the post call works in likes but i think there is something different about the relationship posting stuff, i think you may have to pass a json string or something. I used the instagram api console to do some testing : screen shot 2014-03-28 at 2 45 36 pm

http://instagram.com/developer/api-console/

nickthedude commented 10 years ago

I sent you an invite via skype

wenwuwang commented 10 years ago

nickthedude, have you made follow api work?

nickthedude commented 10 years ago

@wenwuwang no i haven't :( I think the request needs to be in JSON format, but im not sure.

buddyhut commented 10 years ago

HI I am getting same error

omain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0xd5184f0 {NSErrorFailingURLKey=https://api.instagram.com/v1/users/281156948/relationship, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xd297010> { URL: https://api.instagram.com/v1/users/281156948/relationship } { status code: 400, headers { "Cache-Control" = "private, no-cache, no-store, must-revalidate"; Connection = "keep-alive"; "Content-Language" = en; "Content-Length" = 282; "Content-Type" = "application/json; charset=utf-8"; Date = "Fri, 25 Apr 2014 05:45:16 GMT"; Expires = "Sat, 01 Jan 2000 00:00:00 GMT"; Pragma = "no-cache"; Server = nginx; "Set-Cookie" = "csrftoken=684ad3a65af51c97585d3ea98d175b6b; expires=Fri, 24-Apr-2015 05:45:16 GMT; Max-Age=31449600; Path=/"; Vary = "Cookie, Accept-Language"; "X-Ratelimit-Limit" = 5000; "X-Ratelimit-Remaining" = 4980; } }, NSLocalizedDescription=Request failed: bad request (400)}

jaharabari commented 10 years ago

i am also getting same error when we give parameters in NSDictionary. There is some problem in post request with parameters. Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0x17686810 {NSErrorFailingURLKey=https://api.instagram.com/v1/users/31292250/relationship, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x176a49d0> { URL: https://api.instagram.com/v1/users/31292250/relationship } { status code: 400, headers { "Cache-Control" = "private, no-cache, no-store, must-revalidate"; Connection = "keep-alive"; "Content-Language" = en; "Content-Type" = "application/json; charset=utf-8"; Date = "Tue, 13 May 2014 13:13:22 GMT"; Expires = "Sat, 01 Jan 2000 00:00:00 GMT"; Pragma = "no-cache"; Server = nginx; "Set-Cookie" = "csrftoken=e7894bcc14d4e059659de7d4c4730944; expires=Tue, 12-May-2015 13:13:22 GMT; Max-Age=31449600; Path=/"; "Transfer-Encoding" = Identity; Vary = "Cookie, Accept-Language"; } }, NSLocalizedDescription=Request failed: bad request (400)}

fabf98dev commented 10 years ago

@shyambhat @nickthedude @iphonejaha @wenwuwang has anyone already found a solution?

IngenieurinW commented 10 years ago

this has something to do with the scope follow/unfollow must be included in the scope

shyambhat commented 10 years ago

It took me less than 10 mins to implement these simple endpoints. Check out the implementation in the "relationships" branch.

Will merge to master and release in the next version shortly.

nickthedude commented 10 years ago

I tried to tell you I sucked, lol. Thanks for fixing this dude. Next time you're In sf I owe you a beer. :)

v0l0d commented 10 years ago

I've just downloaded from git, launched demo, but it still doesn't work (like fails with the same error) :(

driver733 commented 9 years ago

Is there any solution to this problem? I get the exact same error even for basic requests like "getSelfFeed"

shyambhat commented 9 years ago

@v0l0d you missed read Readme, maybe? For your app to POST or DELETE likes, comments or follows, you must apply to Instagram here : https://www.facebook.com/help/instagram/contact/185819881608116#

@driver733 try re-authenticating.