dongyuji7309 2015-12-29 17:24
浏览 38
已采纳

Laravel Socialite HTTPS twitter头像

I am using laravel 5.0 and utlising the socialite extension to enable twitter login. I encountered a problem with the retrieval of the users twitter profile picture.

The url for the profile picture I receive from twitter is in the following format.

http://pbs.twimg.com/profile_images/662983942727999489/q5I9DMyE_normal.png

This is saved to my db and shown when the user logs into their account. The problem is this image is serving over HTTP and is producing browser warnings when users are accessing their account, as not all the page content is served over HTTPS.

Is there any way to save the twitter profile picture with HTTPS compared to HTTP.

 $user = User::create([
            'provider_id' => $userData->id,
            'name' => $userData->name,
            'username' => $userData->nickname,
            'email' => $userData->email,
            'avatar' => $userData->avatar,
            'active' => 1,
        ]);

I save the user twitter data to my db as shown above and it the $userData->avatar part which is saving the HTTP url.

I can't seem to work a way around this and can't find much documentation on the issue. Any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • duanfeng7756 2015-12-29 19:02
    关注

    Well, verifying this url, it seems simple https:// for the same url works, so you can do:

    $user = User::create([
        'provider_id' => $userData->id,
        'name' => $userData->name,
        'username' => $userData->nickname,
        'email' => $userData->email,
        'avatar' => str_replace('http://','https://',$userData->avatar),
        'active' => 1,
    ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?