Ionic 3 cordova-plugin-facebook4 - There was an error making the graph call. (iOS Only | Android Working)

Using this plugin inside my Ionic 3 project… https://github.com/jeduan/cordova-plugin-facebook4

I’ve done my research and have followed the syntax steps in other issues that I’ve found online. However, I still continue to experience the same problem.

My API call is working in Android Studio, but gives me the generic error, “There was an error making the graph call”, in iOS. In Android, it posts to the proper business page just fine. iOS is the only place giving me the error.

Here is my Ionic Info…

cli packages: (/Users/jacobbradt/Documents/Version 3.0/Mobile App/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 7.0.1 

local packages:

@ionic/app-scripts : 3.0.1
Cordova Platforms  : android 6.2.3 ios 4.4.0
Ionic Framework    : ionic-angular 3.7.1

System:

ios-deploy : 1.9.1 
ios-sim    : 6.0.0 
Node       : v6.11.1
npm        : 3.10.10 
OS         : macOS High Sierra
Xcode      : Xcode 9.4.1 Build version 9F2000 

Below is my function for making the API call using the plugin. Any help would be appreciated. Please note that I’m making an API call to access a Business Page and not a User Account.

this.fb.api(this.requestData.facebook_id + "/?fields=access_token",["manage_pages","publish_pages"])
              .then(res => {
                let access_token = res.access_token;

                let facebookString = this.requestData.facebook_id + "/feed/?fields=id" + "&method=post" + "&link=" + link
                if(this.post.facebook_message != null && this.post.facebook_message != ""){
                  facebookString += "&message=" + this.post.facebook_message;
                }
                facebookString += "&access_token=" + access_token;

                this.fb.api(facebookString,["manage_pages","publish_pages"])
                  .then(res => {
                    this.loading.dismissAll();
                    this.viewCtrl.dismiss('update');
                    let toast = this.toastCtrl.create({
                      message: 'Your Post Was Shared to Facebook!',
                      duration: 3000,
                      position: 'top'
                    });
                    toast.present();
                  })
                  .catch(e => {
                    this.loading.dismissAll();
                    this.viewCtrl.dismiss('update');
                    let toast = this.toastCtrl.create({
                      message: 'Error Sharing Your Post to Facebook',
                      duration: 3000,
                      position: 'top'
                    });
                    toast.present();
                  });
              })
              .catch(e => {
                console.log(e);
              });

Thanks in advance for all your help!

  1. which version of the facebook4 plugin? v2.2.0 is the latest

  2. Have you try to make a try with a simplified version of your code respectively with just the api call? like

       this.fb.api(this.requestData.facebook_id + "/?fields=access_token",["manage_pages","publish_pages"])
                    .then((res) => {
                     console.log(res);
                  }, (err) => {
                     console.log(err);
                  });
    

doing so you get an error or a success?

here’s my current plugin list…

cordova-clipboard 1.0.0 “Clipboard”
cordova-plugin-app-event 1.2.1 “Application Events”
cordova-plugin-badge 0.8.1 “Badges”
cordova-plugin-calendar 4.6.0 “Calendar”
cordova-plugin-camera 2.4.1 “Camera”
cordova-plugin-cocoalumberjack 0.0.4 “CocoaLumberjack”
cordova-plugin-compat 1.1.0 “Compat”
cordova-plugin-console 1.0.5 “Console”
cordova-plugin-device 1.1.4 “Device”
cordova-plugin-facebook4 2.1.0 “Facebook Connect”
cordova-plugin-fcm 2.1.2 “FCMPlugin”
cordova-plugin-file 4.3.3 “File”
cordova-plugin-file-transfer 1.6.3 “File Transfer”
cordova-plugin-filepath 1.0.2 “FilePath”
cordova-plugin-geolocation 2.4.3 “Geolocation”
cordova-plugin-ionic-keyboard 2.0.5 “cordova-plugin-ionic-keyboard”
cordova-plugin-ionic-webview 1.1.7 “Ionic’s WKWebView Engine”
cordova-plugin-splashscreen 5.0.2 “Splashscreen”
cordova-plugin-statusbar 2.2.3 “StatusBar”
cordova-plugin-whitelist 1.3.1 “Whitelist”
de.appplant.cordova.plugin.local-notification 0.8.5 “LocalNotification”
ionic-plugin-deeplinks 1.0.15 “Ionic Deeplink Plugin”

I have success in retrieving the token. However, when it goes to post to Facebook, that’s where the error occurs. I have my local code CONSOLE.LOGing some things out to xCode so you can see what I mean.

Here’s my log from xCODE…

RETURNED PAGE TOKEN
2018-06-30 15:04:47.748228-0500 Rockford Buzz[11257:736620] {“id”:“54685000003347”,“access_token”:“EAAMVzZC9aJgcBAEi9ugkTXbUWdECcfya78YG0SyyVVZAODFvbZBIkDK4LWThggE67oOcI9gELZA1FrzfBTyxUPfB7ZAxueZfdsassdffdZBGRZBzuYECAretrV3aFO2aGHZByEkGJ1qCjCBZBblRQMk2Vfm5SlhYynkFPSTC6y2E5XkywZDZD”}
2018-06-30 15:04:47.749212-0500 Rockford Buzz[11257:736620] FACEBOOK STRING
2018-06-30 15:04:47.749570-0500 Rockford Buzz[11257:736620] 546850000003347/feed/?fields=id&method=post&link=https://rockfordbuzz.com/story/Post-11014&message=Check out our exciting news on Rockford Buzz!&access_token=EAAMVzZC9aJgcBAEi9ugkTXbUWdECcfya78YG0SyyVVZAODFvbZBIkDK4LWThggE67oOcI9gELZA1FrzfBTyxUPfB7ZAxueZAd9ZCNMvsdfdffdssaYECAretrV3aFO2aGHZByEkGJ1qCjCBZBblRQMk2Vfm5SlhYynkFPSTC6y2E5XkywZDZD
2018-06-30 15:04:47.749880-0500 Rockford Buzz[11257:736620] Graph Path = 546800000023347/feed/?fields=id&method=post&link=https://rockfordbuzz.com/story/Post-11014&message=Check out our exciting news on Rockford Buzz!&access_token=EAAMVzZC9aJgcBAEasdfdfsdaCcfya78YG0SyyVVZAODFvbZBIkDK4LWThggE67oOcI9gELZA1FrzfBTyxUPfB7ZAxueZAd9ZCNMvNpZBGRZBzuYECAretrV3aFO2aGHZByEkGJ1qCjCBZBblRQMk2Vfm5SlhYynkFPSTC6y2E5XkywZDZD
2018-06-30 15:04:47.760288-0500 Rockford Buzz[11257:736620] THREAD WARNING: [‘FacebookConnectPlugin’] took ‘10.426025’ ms. Plugin should use a background thread.
2018-06-30 15:04:47.760490-0500 Rockford Buzz[11257:747778] Task <0325A7CE-6449-4EA6-88BD-7BF600367236>.<1> finished with error - code: -1002
2018-06-30 15:04:47.779632-0500 Rockford Buzz[11257:736620] Finished GraphAPI request
2018-06-30 15:04:47.786210-0500 Rockford Buzz[11257:736620] ERROR REPORT
2018-06-30 15:04:47.787678-0500 Rockford Buzz[11257:736620] There was an error making the graph call.

Does really the above code you displayed show that feature? In the above code you make two .api call after the other

 // first call
 this.fb.api(this.requestData.facebook_id + "/?fields=access_token",["ma
     ....
    // second call 
    this.fb.api(facebookString,["manage_pa

which I already don’t understand, why are you making two api requests?

Then you are saying that you can’t post to facebook but I don’t see any references to fb.showDialog, how do you post to Facebook?

The first API call passes the Facebook Page ID to the call in order to retrieve the access_token for the PAGE (as opposed to the token for the user)

The second API call is what does the posting… if you look at my “facebookString” variable, you’ll see that I pass the “method=Post” into the string, telling the graph API that this is a POST not a GET call. The reason for the first API call is to grab the PAGE token (ensuring it’s fresh) in order to pass that token along in the second call which does the actual posting.

and that’s supported?

I can run my request in the Graph Explorer Tool that Facebook provides and it works.

My code is also working in Android, which leads me to believe it’s supported, just not iOS.

Do that error msg comes from your code? could you get more info about the error respectively parse the stacktrace?

also could you double check the syntax of facebookString before doing the api call? maybe there are spaces in the requests, like in the message…

see Error in making the graph call on IOS device · Issue #338 · jeduan/cordova-plugin-facebook4 · GitHub

Yes, that part of the message is from my code… the only thing I get from xCode log is…

Finished GraphAPI request
2018-07-01 15:17:14.584855-0500 Rockford Buzz[16606:1219266] TIC Read Status [6:0x0]: 1:57
2018-07-01 15:17:14.585314-0500 Rockford Buzz[16606:1219266] TIC Read Status [6:0x0]: 1:57
2018-07-01 15:17:14.590796-0500 Rockford Buzz[16606:1204574] ERROR REPORT
2018-07-01 15:17:14.591680-0500 Rockford Buzz[16606:1204574] There was an error making the graph call.
[DEBUG] Did open connection on socket 25
[DEBUG] Did connect
[DEBUG] Did start background task
[DEBUG] Connection received 689 bytes on socket 25
[DEBUG] Connection on socket 25 preflighting request “GET /Users/jacobbradt/Library/Developer/CoreSimulator/Devices/892F80F3-2A8E-4D89-90A7-368874D4BC59/data/Containers/Bundle/Application/CB23AD02-2FBC-416E-854E-D6BAC9F85F71/Rockford Buzz.app/www/build/26.js” with 689 bytes body
[DEBUG] Connection on socket 25 processing request “GET /Users/jacobbradt/Library/Developer/CoreSimulator/Devices/892F80F3-2A8E-4D89-90A7-368874D4BC59/data/Containers/Bundle/Application/CB23AD02-2FBC-416E-854E-D6BAC9F85F71/Rockford Buzz.app/www/build/26.js” with 689 bytes body
[DEBUG] Connection sent 310 bytes on socket 25
[DEBUG] Connection sent 32768 bytes on socket 25
[DEBUG] Connection sent 22998 bytes on socket 25
[DEBUG] Did close connection on socket 25
[VERBOSE] [127.0.0.1:8080] 127.0.0.1:64645 200 “GET /Users/jacobbradt/Library/Developer/CoreSimulator/Devices/892F80F3-2A8E-4D89-90A7-368874D4BC59/data/Containers/Bundle/Application/CB23AD02-2FBC-416E-854E-D6BAC9F85F71/Rockford Buzz.app/www/build/26.js” (689 | 56076)
[DEBUG] Did disconnect
[DEBUG] Did end background task
2018-07-01 15:17:55.053795-0500 Rockford Buzz[16606:1204574] CDVWKWebViewEngine: handleStopScroll
2018-07-01 15:17:55.976786-0500 Rockford Buzz[16606:1204574] CDVWKWebViewEngine: handleStopScroll

Also, I removed the message. No spaces in the Graph Call, but still receive the error. Here’s my Graph Call.

546123452023347/feed/?fields=id&method=post&link=https://rockfordbuzz.com/story/Post-11016&access_token=EAAMVzZC9aJgcBABwqcUCpOCmsXKOIZAvTQhRLGtdCVLEFK0QzM19kvAxxZA6Ws5CnNECA10QKY4X4ZAzW1Pd6ITVN941H111111RjMNPNwqZAbhBFQBzvFxFvNbOR7PUHGszpexE8ZBmKLYzDbZCpCZC7D9ZBDCGrBpJu9mCCUnI4pgZDZD

Maybe try to upgrade to v2.2.0 or downgrade to v1.74 the facebook4 plugin? If one or the other solution might work it would means that there is a bug inside the Facebook iOS SDK

2.2.0 didn’t work.

there is no version 1.74 of that plugin.

freak sorry typing mistake 1.7.4

also that’s the first google search solution to your error msg, did you check that you have both NSAppTransportSecurity and NSAllowsArbitraryLoads in your plist?

The error I’m receiving is 1002. I Google’d the crap out of that thing and didn’t have any luck. Just to be sure, I did check my plist and found the key already there. Here’s the section regarding Transport Security for your review. I’ll give 1.7.4 a try and see what happens

<key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>localhost</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>ionic.local</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>youtube.com/*</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>vimeo.com/*</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>169.254.142.124</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>192.168.1.2</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>192.168.1.182</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>192.168.1.39</key>
        <dict>
          <key>NSExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
        <key>m.facebook.com</key>
        <dict/>
        <key>graph.facebook.com</key>
        <dict/>
        <key>api.facebook.com</key>
        <dict/>
        <key>fbcdn.net</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
        </dict>
      </dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>

tried 1.7.4. experiencing the exact same thing

Thx for the feedback. I’ve to say I’m a bit out of idea, I’ll think about it but the iOS code of the plugin itself didn’t change in ages except the Facebook iOS SDK which according your tests also doesn’t work (old or new, same same). If there is a bug that would mean that you landed on a bug which is there since maybe a long long time and which no one ever faced?

Have you try to reproduce the problem with a totally separate dummy and simple app?

Sometimes with a brand new simple app/platform the problem doesn’t occurs and then it’s possible to compare what’s different…just an idea

I ended up doing a total pivot and posting to graph API using HTTP. Used the exact same string and it worked first time.

Thanks for all of your time, effort, and help.

Nice to hear you found a solution/workaround

can you share how you did this?