facebook-python-business-sdk icon indicating copy to clipboard operation
facebook-python-business-sdk copied to clipboard

Version 2.10.1 Failed to Generate Exception for Invalid Access Token Permission

Open Liguo-AdGo opened this issue 9 years ago • 3 comments

The issue: When API connect to Facebook with an access_token, which is valid to connect but not valid to read an AdObject, the API failed to generate proper exception. It generates the following exception due to failure to retrieve proper data:

File "/usr/local/lib/python2.7/dist-packages/facebookads/adobjects/abstractcrudobject.py", line 364, in remote_read
  self = request.execute()
File "/usr/local/lib/python2.7/dist-packages/facebookads/api.py", line 663, in execute
  api_version=self._api_version,
File "/usr/local/lib/python2.7/dist-packages/facebookads/api.py", line 330, in call
  raise fb_response.error()
File "/usr/local/lib/python2.7/dist-packages/facebookads/api.py", line 130, in error
  self.body(),
File "/usr/local/lib/python2.7/dist-packages/facebookads/exceptions.py", line 80, in __init__
  if self._error.get('error_data', {}).get('blame_field_specs'):
AttributeError: 'unicode' object has no attribute 'get'

Using the offending access_token through Graph API explorer, the following is the result:

{
  "error": {
    "message": "Error validating access token: The user is enrolled in a blocking, logged-in checkpoint",
    "type": "OAuthException",
    "code": 190,
    "error_subcode": 490,
    "error_data": "{\"checkpoint_flow_id\":\"207799259245384\",\"checkpoint_content_id\":\"0\"}",
    "fbtrace_id": "G+SPDLMud4h"
  }
}

Liguo-AdGo avatar Oct 07 '17 15:10 Liguo-AdGo

The same issue still exists in SDK 2.11.3

Liguo-AdGo avatar Feb 20 '18 14:02 Liguo-AdGo

In some situation, this is what comes in as FacebookRequestError.body():

<html lang="en" id="facebook">
  <head>
    <title>Facebook | Error</title>
    <meta charset="utf-8">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="cache-control" content="no-store">
    <meta http-equiv="cache-control" content="max-age=0">
    <meta http-equiv="expires" content="-1">
    <meta http-equiv="pragma" content="no-cache">
    <meta name="robots" content="noindex,nofollow">
    <style>
      html, body {
        color: #141823;
        background-color: #e9eaed;
        font-family: Helvetica, Lucida Grande, Arial,
                     Tahoma, Verdana, sans-serif;
        margin: 0;
        padding: 0;
        text-align: center;
      }

      #header {
        height: 30px;
        padding-bottom: 10px;
        padding-top: 10px;
        text-align: center;
      }

      #icon {
        width: 30px;
      }

      h1 {
        font-size: 18px;
      }

      p {
        font-size: 13px;
      }

      #footer {
        border-top: 1px solid #ddd;
        color: #9197a3;
        font-size: 12px;
        padding: 5px 8px 6px 0;
      }
    </style>
  </head>
  <body>
    <div id="header">
      <a href="//www.facebook.com/">
        <img id="icon" src="//static.xx.fbcdn.net/images/logos/facebook_2x.png" />
      </a>
    </div>
    <div id="core">
      <h1 id="sorry">Sorry, something went wrong.</h1>
      <p id="promise">
        We're working on it and we'll get it fixed as soon as we can.
      </p>
      <p id="back-link">
        <a id="back" href="//www.facebook.com/">Go Back</a>
      </p>
      <div id="footer">
        Facebook
        <span id="copyright">
          &copy; 2018
        </span>
        <span id="help-link">
          &#183;
          <a id="help" href="//www.facebook.com/help/">Help Center</a>
        </span>
      </div>
    </div>
    <script>
      document.getElementById('back').onclick = function() {
        if (history.length > 1) {
          history.back();
          return false;
        }
      };

      // Adjust the display based on the window size
      if (window.innerHeight < 80 || window.innerWidth < 80) {
        // Blank if window is too small
        document.body.style.display = 'none';
      };
      if (window.innerWidth < 200 || window.innerHeight < 150) {
        document.getElementById('back-link').style.display = 'none';
        document.getElementById('help-link').style.display = 'none';
      };
      if (window.innerWidth < 200) {
        document.getElementById('sorry').style.fontSize = '16px';
      };
      if (window.innerWidth < 150) {
        document.getElementById('promise').style.display = 'none';
      };
      if (window.innerHeight < 150) {
        document.getElementById('sorry').style.margin = '4px 0 0 0';
        document.getElementById('sorry').style.fontSize = '14px';
        document.getElementById('promise').style.display = 'none';
      };
    </script>
  </body>
</html>

Liguo-AdGo avatar Feb 27 '18 18:02 Liguo-AdGo

It seems like this issue has been open for more than a few months now. We have made many changes in the SDK since then, including releasing a new version. If you can repro your specific issue with the latest version of the SDK, please create a new issue or comment here with further details.

codytwinton avatar Aug 27 '18 18:08 codytwinton