joshuadunlop commited on
Commit
1e10a71
·
verified ·
1 Parent(s): 6ac5e4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -8
app.py CHANGED
@@ -25,10 +25,6 @@ def get_backlinks(api_login, api_key, target_url, filters):
25
  # Making the API request
26
  response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
27
 
28
- # Log the full response for debugging
29
- st.text("API Response:")
30
- st.json(response.json()) # This will display the full JSON response in the Streamlit app
31
-
32
  # Check if the response contains 'results' key
33
  if response.status_code == 200:
34
  response_data = response.json()
@@ -36,16 +32,13 @@ def get_backlinks(api_login, api_key, target_url, filters):
36
  if 'results' in response_data:
37
  results = response_data['results']
38
  if results:
39
- # The line below needs to be adjusted according to the actual structure of 'results'
40
- # For example, if results is a list of dictionaries, this should work as is.
41
- # If the structure is more nested, you'll need to specify the path correctly.
42
  df = pd.json_normalize(results)
43
  return df
44
  else:
45
  st.error("Received empty data from API.")
46
  return None
47
  else:
48
- # Handle other internal status codes here
49
  internal_status_code = response_data.get('status_code', None)
50
  internal_status_message = response_data.get('status_message', 'No specific message provided')
51
  st.error(f"Internal Status Code: {internal_status_code}, Message: {internal_status_message}")
 
25
  # Making the API request
26
  response = requests.post("https://api.dataforseo.com/v3/backlinks/backlinks/live", json=post_data, headers=headers)
27
 
 
 
 
 
28
  # Check if the response contains 'results' key
29
  if response.status_code == 200:
30
  response_data = response.json()
 
32
  if 'results' in response_data:
33
  results = response_data['results']
34
  if results:
35
+ # Normalize the JSON data into a pandas DataFrame
 
 
36
  df = pd.json_normalize(results)
37
  return df
38
  else:
39
  st.error("Received empty data from API.")
40
  return None
41
  else:
 
42
  internal_status_code = response_data.get('status_code', None)
43
  internal_status_message = response_data.get('status_message', 'No specific message provided')
44
  st.error(f"Internal Status Code: {internal_status_code}, Message: {internal_status_message}")