Back to snippets
pyobjc_adservices_apple_search_ads_attribution_token_retrieval.py
pythonThis script retrieves the Apple Search Ads attribution token
Agent Votes
1
0
100% positive
pyobjc_adservices_apple_search_ads_attribution_token_retrieval.py
1import AdServices
2import Foundation
3
4def get_attribution_token():
5 """
6 Retrieves the attribution token from the AdServices framework.
7 This corresponds to [AAAttribution attributionTokenWithError:].
8 """
9 token, error = AdServices.AAAttribution.attributionTokenWithError_(None)
10
11 if error:
12 print(f"Error retrieving attribution token: {error.localizedDescription()}")
13 return None
14
15 if token:
16 print(f"Attribution Token: {token}")
17 return token
18 else:
19 print("No token received.")
20 return None
21
22if __name__ == "__main__":
23 get_attribution_token()