使用JQuery获取Twitter个人资料图片网址

时间:2012-07-19 17:59:30

标签: url jquery twitter syntax-error image

我想使用JQuery

简单地检索Twitter个人资料图片的网址

为此我使用:

$.ajax({
    type: "GET",
    url: "https://api.twitter.com/1/users/profile_image/twitterapi.json",
    dataType: "jsonp",
    success: function(data){
        console.log('success');
    },
    error: function(data){
        console.log('error');
    }

});

但是我收到了这个错误

Uncaught SyntaxError: Unexpected token ILLEGAL

任何人都知道我的错误在哪里?

2 个答案:

答案 0 :(得分:1)

  

未捕获的SyntaxError:意外的标记ILLEGAL

尝试在浏览器中打开该网址。您将被“重定向”到其他URL。通过curl -v验证并检查Location: ...标题。


解决方案是从url:

请求JSONP

https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true&callback=foo

您将从根对象的profile_image_url字段中获取图片网址。

答案 1 :(得分:1)

这是一个静态网址,可以获取最新的推特个人资料图片网址。

from django.test.runner import DiscoverRunner
from django.apps import apps
import sys

class UnManagedModelTestRunner(DiscoverRunner):
    """
    Test runner that uses a legacy database connection for the duration of the test run.
    Many thanks to the Caktus Group: https://www.caktusgroup.com/blog/2013/10/02/skipping-test-db-creation/
    """
    def __init__(self, *args, **kwargs):
        super(UnManagedModelTestRunner, self).__init__(*args, **kwargs)
        self.unmanaged_models = None
        self.test_connection = None
        self.live_connection = None
        self.old_names = None

    def setup_databases(self, **kwargs):
        # override keepdb so that we don't accidentally overwrite our existing legacy database
        self.keepdb = True
        # set the Test DB name to the current DB name, which makes this more of an
        # integration test, but HEY, at least it's a start
        DATABASES['legacy']['TEST'] = { 'NAME': DATABASES['legacy']['NAME'] }
        result = super(UnManagedModelTestRunner, self).setup_databases(**kwargs)

        return result

# Set Django's test runner to the custom class defined above
TEST_RUNNER = 'config.settings.test_settings.UnManagedModelTestRunner'
TEST_NON_SERIALIZED_APPS = [ 'legacy_app' ]

我的twitter用户屏幕名称是rkramakrishna17

 https://twitter.com/{{#twitterUserName}}/profile_image?size=normal

修改1:

根据@juanmirocks的建议,我们可以通过添加?size = origianl来获取原始图像以获得原始图像。

https://twitter.com/rkramakrishna17/profile_image?size=normal