这是我的代码,当我运行它时,我在第19行(对于循环)出现错误:TypeError:对象"int"不可迭代。
import fb
from facepy import GraphAPI
token=""# access token here.
facebook=fb.graph.api(token)
graph1 = GraphAPI(token)
vid="" #page id here
query=str(vid)+"/feed"
r=graph1.get(query)
count=0
nos=input("Enter number of posts: ")
for indid in nos:
count=count+1
facebook.publish(cat="feed",id=indid,message="Hi"+str(count))
time.sleep(6)
print("Wall post:"+str(count))
else :
print("No posts made.")
请告诉我怎么了。
好吧,错误说明了一切:您试图在以下代码的for
循环中迭代int
:
nos=input("Enter number of posts: ") # nos is an int here
for indid in nos: # and this is not how you iterate over an int
count=count+1
facebook.publish(cat="feed",id=indid,message="Hi"+str(count))
改为设置一个范围:
for count in range(0, nos):
facebook.publish(cat="feed",id=count,message="Hi"+str(count))
此外:我不知道你想用indid
做什么。也许你也想找一个你想换的职位。。。