我有一個使用「gdshortener」模塊生產我的源URL縮短版的一些代碼:字符串轉換不生產所需的值
import simplejson
import httplib2
import twitter
import gdshortener
from random import randint
print("Python will now attempt to submit tweets to twitter...")
try:
api = twitter.Api(consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
b = 0
for a in range(0, 1): #only range 0-1 for this question, actually 1-21
b = b + 1
a = randint(1,60000000)
randint
print ("a = ", a)
aa = str(a)
s1 = gdshortener.ISGDShortener()
print s1.shorten(url = 'http://audiotechracy.blogspot.co.uk/2014/03/reviewing-synapse-antidote-rack.html', custom_url = aa)
ss1 = str(s1)
status = api.PostUpdate("The new Synapse Antidote Rack Extension:" + ss1 + " #propellerhead #synapse")
print("Tweets submitted successfully!")
except Exception,e:
print str(e)
print("Twitter submissions have failed!!!")
我使用的是隨機數發生器來產生六位數然後將這些數字提供給此模塊的custom_url參數。這很好,我得到了一系列僞隨機數。但是,當我試着連接我的推特字符串,我的動態短網址和一些井號標籤時,我收到一個錯誤,我無法連接字符串和整數值。
所以我然後創建的變量「SS1」,這是「S1」的字符串,但是這現在產生這樣的鳴叫:
The new Synapse Antidote Rack Extension:<gdshortener.gdshortener.ISGDShortener object at 0x000000000542AA20> #propellerhead #synapse
我怎樣才能得到它,這樣產生的鳴叫是:
The new Synapse Antidote Rack Extension: http://is.gd/58077181 #propellerhead #synapse
感謝
'ISGDShortener()'方法不會返回可以簡單地轉換爲字符串的對象。您可以查看API文檔或鍵入'dir(s1)'並查看當前正在使用的對象的屬性/方法。 – Matthew