mirror of
https://github.com/guyzyl/google-contacts-fix.git
synced 2026-04-24 21:55:51 +03:00
Auto add/fix country code of Google Contacts
- Python 100%
| .gitignore | ||
| claude.md | ||
| fix_contacts.py | ||
| LICENSE | ||
| README.md | ||
| requirements.txt | ||
Google Contacts Country Code Fixer
A Python script that automatically adds country codes to phone numbers in your Google Contacts that are missing them. Perfect for when you move to a new country and need to update your contacts for WhatsApp and other apps.
Features
- OAuth2 authentication with Google
- Downloads all your Google contacts
- Identifies phone numbers without country codes
- Adds specified country code to those numbers
- Updates contacts back to Google
- Dry-run mode to preview changes before applying
- Confirmation prompt before making changes
Setup Instructions
1. Install Python Dependencies
pip install -r requirements.txt
2. Set Up Google Cloud Project
-
Go to the Google Cloud Console
-
Create a new project (or select an existing one)
-
Enable the People API:
- Click on "Enable APIs and Services"
- Search for "People API"
- Click "Enable"
-
Create OAuth 2.0 Credentials:
- Go to "Credentials" in the left menu
- Click "Create Credentials" → "OAuth client ID"
- If prompted, configure the OAuth consent screen:
- Choose "External" user type
- Fill in required fields (app name, user support email, developer email)
- Add your email as a test user
- Save and continue through the screens
- Back in Credentials, create "OAuth client ID"
- Choose "Desktop app" as the application type
- Give it a name (e.g., "Contacts Fixer")
- Click "Create"
-
Download the credentials:
- Click the download icon (⬇) next to your newly created OAuth 2.0 Client ID
- Save the file as
credentials.jsonin the same directory asfix_contacts.py
3. Run the Script
First Time Use
The first time you run the script, it will open a browser window asking you to authorize the application:
python fix_contacts.py --country-code +972
- A browser will open automatically
- Select your Google account
- You may see a warning that the app isn't verified - click "Advanced" and then "Go to [your app name] (unsafe)"
- Click "Allow" to grant access to your contacts
- The script will save your authorization token for future use
Preview Changes (Dry Run)
To see what changes would be made without actually updating contacts:
python fix_contacts.py --country-code +972 --dry-run
Update Contacts
To actually update your contacts:
python fix_contacts.py --country-code +972
Usage
python fix_contacts.py [OPTIONS]
Options:
--country-code CODE Country code to add (e.g., +972 for Israel, +1 for US)
Default: +972
--dry-run Preview changes without updating contacts
-h, --help Show help message
Examples
# Add Israel country code (+972)
python fix_contacts.py --country-code +972
# Add US country code (+1)
python fix_contacts.py --country-code +1
# Preview changes without updating
python fix_contacts.py --country-code +972 --dry-run
# Country code without + symbol (will be added automatically)
python fix_contacts.py --country-code 972
How It Works
- Authentication: Uses OAuth2 to securely access your Google Contacts
- Fetch: Downloads all contacts with their phone numbers
- Identify: Finds phone numbers that don't start with
+ - Process: Adds the specified country code (removes leading zeros first)
- Update: Updates the contacts back to Google (with confirmation)
Example Output
============================================================
Google Contacts Country Code Fixer
============================================================
Country code: +972
Mode: LIVE UPDATE
============================================================
Fetching contacts...
Found 150 contacts
Scanning for phone numbers without country codes...
John Doe: 0501234567 → +972501234567
Jane Smith: 0541234567 → +972541234567
Bob Johnson: 0521234567 → +972521234567
Found 3 contacts that need updating
Proceed with updates? (yes/no): yes
Updating 3 contacts...
✓ Updated John Doe
✓ Updated Jane Smith
✓ Updated Bob Johnson
Results: 3 successful, 0 failed
✓ Done!
Security Notes
- Your credentials are stored locally in
credentials.json - Your authorization token is stored locally in
token.json - The script only requests access to your contacts (read and write)
- Never share your
credentials.jsonortoken.jsonfiles
Troubleshooting
"credentials.json not found"
- Make sure you've downloaded the OAuth credentials from Google Cloud Console
- The file must be named exactly
credentials.json - Place it in the same directory as
fix_contacts.py
"App isn't verified" warning
- This is normal for personal projects
- Click "Advanced" and then "Go to [your app name] (unsafe)"
- This is safe because you created the app yourself
"Access denied" or authentication errors
- Delete
token.jsonand run the script again - Re-authenticate when prompted
Numbers not updating correctly
- Use
--dry-runfirst to see what changes will be made - The script removes leading zeros before adding country codes
- If you see unexpected results, please check the original format of your numbers
Common Country Codes
- Israel:
+972 - United States/Canada:
+1 - United Kingdom:
+44 - Australia:
+61 - Germany:
+49 - France:
+33 - India:
+91 - Japan:
+81
License
This script is provided as-is for personal use.