title: Instagram Graph API - Avoid "Media Posted Before Business Account Conversion" error in swift
body: <p>I am trying to get data from instagram through the instagram Graph API. For that, I use a url with a parameter called limit, which returns a Json. Limit will always be over 1, and can go up to 12. Limit is representative of how many of the last posts you want to get.</p>
  <p>This limit must be equal to the number of posts the user have posted on his/her Instagram. If you ask a limit that is below, you won't get all the posts. If it's over, the Json response is an error.</p>
  <p>The error Json:</p>
  <pre><code>{
     &quot;error&quot;: {
        &quot;message&quot;: &quot;Invalid parameter&quot;,
        &quot;type&quot;: &quot;OAuthException&quot;,
        &quot;code&quot;: 100,
        &quot;error_data&quot;: {
           &quot;blame_field_specs&quot;: [
              [
                 &quot;&quot;
              ]
           ]
        },
        &quot;error_subcode&quot;: 2108006,
        &quot;is_transient&quot;: false,
        &quot;error_user_title&quot;: &quot;Media Posted Before Business Account Conversion&quot;,
        &quot;error_user_msg&quot;: &quot;The media was posted before the most recent time that the user's account was converted to a business account from a personal account.&quot;
     }
  }
  </code></pre>
  <p>So far my idea was to try 12 urls, count how many of them were valid and return the right limit. It was working well until recently, when I found out the API could fail to return an error in 100% of cases.</p>
  <p>this is my code:</p>
  <pre><code>//Find url limit
  extension GetJson {
      class func findMediaLimit(IgBusinessAccount: String, token: String, Completion block: @escaping ((Int) -&gt; ())) {
          
          let igBId = IgBusinessAccount
          let group = DispatchGroup()
          var mCount: [Int] = []
      
          
          for i in 1...12 {
              
              guard let encodedUrl = self.buildURLAPIGraph(IgBusinessAccount: igBId, token: token, i: i) else { return }
              
              
              group.enter()
              self.cURL(urlT: encodedUrl) { (Json) in
                  
                  if Json.username != nil {
                      print(&quot;\n\nR with \(i):&quot;)
                      print(Json.media ?? &quot;no&quot;)
                      print(&quot;\n\n&quot;)
                      print(encodedUrl)
                      print(&quot;\n\n&quot;)
                      mCount.append(1)
                  }
                  
                  group.leave()
              }
          }
          
          group.notify(queue: .main) {
              print(&quot;Media limit: \(mCount.count)&quot;)
              block(mCount.count)
          }
      }
  }
  </code></pre>
  <p>Here I'm testing if the Json is valid with &quot;Json.username != nil&quot;
  But I found out that even with a wrong limit it sometimes enters the condition because the API sometimes fails to return an error.</p>
  <p>So this isn't the best way to avoid &quot;Media Posted Before Business Account Conversion&quot;</p>
  <p>Idealy knowing this limit from the API would be great but I don't think this feature exists. Otherwise anybody have an idea how I could do?</p>