Facebook Graph Api Fan page photo upload (IOS) -


i have app uploaded photos on fly , i'm trying add ability upload users facebook fan page (that administer).

the problem i'm having can sucessfully upload photo fan page it's not showing on fan page timeline, it's showing under "recent posts others" section of fan page.

i'm not uploading these images properly. here's code:

acaccounttype * accounttype = [_accountstore accounttypewithaccounttypeidentifier:acaccounttypeidentifierfacebook];         [_accountstore requestaccesstoaccountswithtype:accounttype options:@{acfacebookappidkey: @"xxxxxxxxxxxx", acfacebookpermissionskey : @[@"photo_upload",@"publish_stream", @"publish_actions", @"manage_pages"], acfacebookaudiencekey : acfacebookaudienceeveryone} completion:^(bool granted, nserror *error) {             if (granted) {                  nsarray * accounts = [_accountstore accountswithaccounttype:accounttype];                  nsdictionary *fanpages = [[nsuserdefaults standarduserdefaults] objectforkey:facebook_pref_fan_pages_ids];                  //if using fan pages                 if (fanpages.count)                 {                      (id key in fanpages) {                         //id key , access token value                         nslog(@"access token:%@, fanpage id: %@", fanpages[key], key);                          nsmutablestring *requesturl = [nsmutablestring stringwithformat:@"https://graph.facebook.com/%@/photos/", key];                          nsurl * url = [nsurl urlwithstring:requesturl];                          nsdictionary *parameters = @{@"access_token": [fanpages[key] stringbyaddingpercentescapesusingencoding:nsutf8stringencoding], @"no_story":@"0", @"message": hashtags};                          slrequest *request = [slrequest requestforservicetype:slservicetypefacebook requestmethod:slrequestmethodpost url:url parameters:parameters];                          [request addmultipartdata:uiimagejpegrepresentation(image, 0.9) withname:@"source" type:@"application/octet-stream" filename:@"media.png"];                         //nslog(@"%@",[accounts lastobject]);                         [request setaccount:[accounts lastobject]];                          //make request                         [request performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) {                             nslog(@"uploaded %@",fanpages[key]);                              nsstring *respdata = [[nsstring alloc] initwithdata:responsedata                                                                        encoding:nsutf8stringencoding];                              nslog(@"responsedata %@",respdata);                             nslog(@"urlresponse %@",urlresponse);                               [self performselectoronmainthread:@selector(removeprogressview) withobject:nil waituntildone:no];                          }];                      }                    }                 else                 {                     //upload personal timeline                     nsurl * url = [nsurl urlwithstring:@"https://graph.facebook.com/me/photos"];                     slrequest *request = [slrequest requestforservicetype:slservicetypefacebook requestmethod:slrequestmethodpost url:url parameters:nil];                     [request addmultipartdata:[hashtags datausingencoding:nsutf8stringencoding] withname:@"message" type:@"multipart/form-data" filename:nil];                     [request addmultipartdata:uiimagejpegrepresentation(image, 0.9) withname:@"source" type:@"application/octet-stream" filename:@"media.png"];                     [request setaccount:[accounts lastobject]];                     [request performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) {                         [self performselectoronmainthread:@selector(removeprogressview) withobject:nil waituntildone:no];                     }];                 }              } else {                  //theres error or not granted              } 

any ideas on i'm doing wrong? i've scoured internet days on 1 , seems correct.

so turns out doing correctly, problem if left in:

[request setaccount:[accounts lastobject]]; 

this causes post on behalf , wouldn't show in timeline. removing code remedied issue , posts showing on fan pages timeline fan page , not facebook user account.

thanks tobi, kinda knew access token , thought passing correctly, apparently wasn't.

so re-iterate, don't use setaccount when posting fan page overwrite access_token user token , not fan page token.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -