Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Tweet.py example
-
Hello - brand new to Python. I’m trying to test the Tweet.py example. I’ve add my twitter handle but still get an error. This script doen’t need any active twitter account on my iOS device setup does it? I mean, I do have one, but it shouldn’t matter, right?
# coding: utf-8 import twitter def main(): accounts = twitter.get_all_accounts() if not accounts: print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.') account = accounts[0] username = account['richexperiences'] print('Loading recent tweets in %s\'s timeline...' % (username,)) tweets = twitter.get_home_timeline(account) for tweet in tweets: print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text'])) print('-' * 40) if __name__ == '__main__': main()
-
If the code in tweet.py is exactly the same as what you showed us, you’re missing a # before the coding: utf-8. Corrected, you would have to change your first line to
#coding: utf-8
The # is commonly used for commenting your code in normal language, as it tells the python interpreter that the following line is no actual python code and can therefore be ignored. The interpreter makes your code understandable for machines and therefore executable also.
If you want to know more or this is not the correct answer, just ask again and again and again 😋
-
Oh, and your last two lines should be:
if __name__ == '__main__': main()
This should be a working version:
# coding: utf-8 import twitter def main(): accounts = twitter.get_all_accounts() if not accounts: print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.') account = accounts[0] username = account['username'] print('Loading recent tweets in %s\'s timeline...' % (username,)) tweets = twitter.get_home_timeline(account) for tweet in tweets: print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text'])) print('-' * 40) if __name__ == '__main__': main()
-
@Drizzel, I am looking at your replies over and over again and feel I must be missing something. In both replies you suggest changing code to what @richexperiences has actually already presented.
It seems to me that in both cases the code ALREADY states what you are suggesting it should be changed to,
@Drizzel, could you please clarify what the differences are between the code as already written and the code you suggest it be changed to?
-
-
@richexperiences, what is the error?
The code itself says:
print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')
So you do need to have a Twitter account configured on the device, and you need to have approved access to the account.
-
The
twitter
module no longer works on recent iOS versions, because iOS no longer has any special native support for Twitter. Quoting the in-app docs for thetwitter
module:Warning: Unfortunately, this module no longer works on iOS 11 and later because the underlying APIs have been removed from iOS.
-
@dgelessus - are you saying flat out that as of IOS 11 there is no way to get Pythonista (or any other IOS app ) to talk to Twitter? Since there is no native apis, there can be no straightforward way tor any IOS app ( other than presumably the Twitter app itself) to code ro Twitter?
-
@ltddev, Twitter provides an online (URL-based) API, and there are several Python implementations for using it (see here for the first nine). Since there is no obvious reason for them to include C components, most of them will probably work with Pythonista. To give them a try, it is best to first install stash, if you have not yet done so.
-
This post is deleted!