小编Joh*_*nny的帖子

python:获取频道的所有YouTube视频网址

我想获取特定频道的所有视频网址.我认为使用python或java的json将是一个不错的选择.我可以使用以下代码获取最新视频,但如何获得所有视频链接(> 500)?

import urllib, json
author = 'Youtube_Username'
inp = urllib.urlopen(r'http://gdata.youtube.com/feeds/api/videos?max-results=1&alt=json&orderby=published&author=' + author)
resp = json.load(inp)
inp.close()
first = resp['feed']['entry'][0]
print first['title'] # video title
print first['link'][0]['href'] #url
Run Code Online (Sandbox Code Playgroud)

python youtube youtube-api

7
推荐指数
4
解决办法
2万
查看次数

在python中制作facebook墙贴

我想在我的脸书粉丝页面上制作一个简单的Wall Post.我有我的APP_ID + APP SECRET,我能够获得访问令牌,但我正在使用facebook.GraphAPI()这是代码:

# -*- coding: utf-8 -*-

import urllib
import facebook

FACEBOOK_APP_ID = '12345'
FACEBOOK_APP_SECRET = '123456789'
FACEBOOK_PROFILE_ID = '321321321321'
oauth_args = dict(
  client_id = FACEBOOK_APP_ID,
  client_secret = FACEBOOK_APP_SECRET,
  grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?'
  + urllib.urlencode(oauth_args)).read()

# oauth_response looks like this:
# access_token=2732467743847839726|3gddzdg3Wl-5S_Go      

attach = {
  "name": 'Hello',
  "link": 'http://www.link.com',
  "caption": 'test',
  "description": 'some test',
  "picture" : 'http://img/picture.png',
}

facebook_graph = facebook.GraphAPI(oauth_response.split('=')[1])
try:
    response = facebook_graph.put_wall_post('', attachment=attach)
except facebook.GraphAPIError as e:
    print e
Run Code Online (Sandbox Code Playgroud)

当我运行脚本时,我收到此错误:

Traceback (most …
Run Code Online (Sandbox Code Playgroud)

python facebook

4
推荐指数
2
解决办法
4588
查看次数

为什么这是一个无休止的循环

我刚刚浏览了python docs教程的循环技术章节,我在这里有一个关于这个男孩的问题: [:]

我了解到它需要字符串的开始和结束索引,因此:

text = "This is text"
text[:] # will return the whole text "This is text" and
tex[:4] # will return "This".
Run Code Online (Sandbox Code Playgroud)

但是当我在这里看到这段代码时......

words = ['cat', 'dog', 'cowcowcow']
for w in words[:]:  # Loop over a slice copy of the entire list.
    if len(w) > 6:
        words.insert(0, w)
print words
Run Code Online (Sandbox Code Playgroud)

输出:

['cowcowcow', 'cat', 'dog', 'cowcowcow']
Run Code Online (Sandbox Code Playgroud)

...我不理解for循环中[:]的含义.我会写的

for w in words:
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,这是一个无休止的循环,为什么呢?

python loops list infinite-loop

1
推荐指数
1
解决办法
362
查看次数

标签 统计

python ×3

facebook ×1

infinite-loop ×1

list ×1

loops ×1

youtube ×1

youtube-api ×1