Laravel Authentication with external API - php

I have an external server API made with node JS and mongo. I suppose user API is localhost:8010/api/login output how do I use that for auth in laravel ?
"users": [
{
"_id": "592e71bc05be3c26f6bda51d",
"updatedAt": "2017-05-31T07:33:16.608Z",
"createdAt": "2017-05-31T07:33:16.608Z",
"userToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiRW1qb3kiLCJkYXRlIjoxNDk2MjE1OTk2NTk0fQ.25AY8EGoCmpcToidVWBU_czOKCFbV-dkrmCPUx6InD4",
"name": "desert",
"mobile": "123456789",
"type": "N",
"is_active": 1,
"__v": 0
}

Auth::login method will see your desired job
$model = User::find(1);
Auth::login($model, true);

Related

Send Current URL link to A Discord Webhook

So, basically I need a way to send the current URL link to A Discord webhook.
So for example, the URL would be https://www.example.com and I need that link to send to my Discord webhook.
Is there any way someone could help me with this? If this is not possible, are there any alternative methods?
I would recommend you first reading this—it explains in detail how to format the payload so that it renders as a message in Discord properly, you can even use markdown!
Second, I'm not sure what language you want to code this in, but here's a simple example using Python and httpx
The idea to take away here is
Pick a client library
Study the Discord webhook message format
Create a client for HTTP
Set the logic to send the payload to the webhook you want
Create and send the payload with the formatted webhook message in a POST request
data = {
"username": "Webhook",
"avatar_url": "https://i.imgur.com/4M34hi2.png",
"content": "Text message. Up to 2000 characters.",
"embeds": [
{
"author": {
"name": "Birdie♫",
"url": "https://www.reddit.com/r/cats/",
"icon_url": "https://i.imgur.com/R66g1Pe.jpg"
},
"title": "Title",
"url": "https://google.com/",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink](https://google.com) `code`",
"color": 15258703,
"fields": [
{
"name": "Text",
"value": "More text",
"inline": true
},
{
"name": "Even more text",
"value": "Yup",
"inline": true
},
{
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
},
{
"name": "Thanks!",
"value": "You're welcome :wink:"
}
],
"thumbnail": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg"
},
"image": {
"url": "https://upload.wikimedia.org/wikipedia/commons/5/5a/A_picture_from_China_every_day_108.jpg"
},
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": "https://i.imgur.com/fKL31aD.jpg"
}
}
]
}
import httpx # pip install httpx, or poetry add httpx
with httpx.Client() as client:
request = client.post("https://www.discordwebhook.com", data=data) # needs to be a POST
print(request.status_code)

How do i make a variable value changeable in different blocks of code in php,laravel

The task is to fetch json user data from an api and store it in array. Then be able to make changes to it different routes.
Here is a sample of the data from the api, they are 10 in total and in an array.
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna#melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
},
i fetched the data using this:
$jsonurl = "http://jsonplaceholder.typicode.com/users";
$json = file_get_contents($jsonurl);
global $userData;
$userData = json_decode($json);
I displayed the data in a /users route with this
Route::get('/users', function(){
global $userData;
echo json_encode($userData);
});
I was told to get set a /delete route that deletes the last object from the array.
Route::get('/delete', function(){
global $userData;
$lastObjIndex = count($userData) -1;
array_splice($userData, $lastObjIndex,1);
//print_r('last user deleted');
echo json_encode($userData);
$userData = $userData;
});
The problem is that the delete route does not only works once(it does not delete subsequent last objects and returns the same thing when the route is accessed again) and does not show any change in when i access the users route. The data isn't stored in the server.
I feel there is something i don't know about that could help with this. Any suggestion would be appreciated.

Get instagram user analytics by username

I want to get the instagram user analytics, i. e. to get the time sheet with count of followers and followings.
Is there any way to get the data from instagram api?
Or Is there other sites that I can get the analytics automatically with PHP?
No analytics API from Instagram yet. we have to search users by user id.
https://www.instagram.com/developer/endpoints/users/#get_users
In the api response the user json contains "counts" for followers, following and medias.
If you just has usernames with you then first search the users from user name by https://www.instagram.com/developer/endpoints/users/#get_users_search; get ids from them and use above API.
To generate the trend; we have to make the API calls daily, for all users!
very costly, but there is no direct API available from Insta yet.
However, FB just released new API for user insights under graph api.
https://developers.facebook.com/docs/instagram-api/reference/user#insights
this works only for instagram business accounts though. and you need the access tokens on behalf of the account you want insights for.
As of 2019-06 you can only access analytics (they call it insights at FB) for your own profile. You can't access insights of other user profile.
For example, let's get your own followers_count.
graph.facebook.com
/{your_facebookPage_id}/insights?metric=followers_count&period=day
You get this JSON as response:
{
"insights": {
"data": [
{
"name": "follower_count",
"period": "day",
"values": [
{
"value": 2,
"end_time": "2019-06-24T07:00:00+0000"
},
{
"value": 0,
"end_time": "2019-06-25T07:00:00+0000"
}
],
"title": "Follower Count",
"description": "Total number of unique accounts following this profile",
"id": "{your_facebookPage_id}/insights/follower_count/day"
}
],
"paging": {
"previous": "https://graph.facebook.com/v3.3/{your_facebookPage_id}/insights?access_token=...&pretty=0&metric=follower_count&period=day&since=1561115213&until=1561288013",
"next": "https://graph.facebook.com/v3.3/{your_facebookPage_id}/insights?access_token=...&pretty=0&metric=follower_count&period=day&since=1561460815&until=1561633615"
}
},
"id": "{your_facebookPage_id}"
}
I used this API
https://graph.facebook.com/v3.2/{ig-user-id}?fields=business_discovery.username(ig-username){followers_count,media_count,media{comments_count,like_count}}&access_token={access-token}
Of course, it does not provide full analytics, but you can get a lot of information about users through username. And response will be:
{
"business_discovery": {
"followers_count": 267793,
"media_count": 1205,
"media": {
"data": [
{
"comments_count": 50,
"like_count": 5841,
"id": "17858843269216389"
},
{
"comments_count": 11,
"like_count": 2998,
"id": "17894036119131554"
},
{
"comments_count": 28,
"like_count": 3644,
"id": "17894449363137701"
},
{
"comments_count": 43,
"like_count": 4943,
"id": "17844278716241265"
},
{
"comments_count": 60,
"like_count": 9347,
"id": "17899363132086521"
},
{
"comments_count": 63,
"like_count": 6913,
"id": "17893114378137541"
},
{
"comments_count": 16,
"like_count": 2791,
"id": "17886057709171561"
},
{
"comments_count": 15,
"like_count": 3895,
"id": "17856337633208377"
},
],
},
"id": "17841401441775531"
},
"id": "17841405976406927"
}

Magento POST requests throwing 403

I've a magento 1.9.1 community instance setup and I'm trying to access them via REST API . I'm able to perform GET requests for Products/Customers etc but I'm stuck while adding a product using a POST request. My sample code is below. Where am I going wrong ?
from requests_oauthlib import OAuth1 as OAuth
import requests
import json
oauth = OAuth(client_key=consumer_key,
client_secret=consumer_secret,
resource_owner_key=access_key,
resource_owner_secret=access_secret)
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
product = """{
"type_id": "simple",
"attribute_set_id": "4",
"sku": "Test",
"name": "Test",
"price": "100",
"description": "Random description",
"short_description": "Random",
"weight": "500",
"status": "1",
"visibility": "4",
"tax_class_id": "2"
}"""
payload = json.loads(product)
uri = "http://magentohost/api/rest/products"
r = requests.post(url=uri, data=json.dumps(payload),headers=headers, auth=oauth)
print r

Facebook - Get & Display me/og.likes in Video application

Have built an video app that publish user actions towards Facebook.
In this app i have implemented an "Favorite" function that i have hooked up towards a basic open graph action "og.like"
I want to be able to display video's that user liked and apply my own styling to that.
Basically i want to display "Title" "Url" & "Image"
So i use the PHP-SDK towards authored user with active access token and execute
$response = $facebook->api(
'me/og.likes',
'GET'
);
// handle the response
How do i now sort out my correct fields and display them ?
Am not hardcore at either php or javascript but will be able to sort this out if i just can get a little push in the right direction. Like just showing the raw data
Update
Finally a little progress, adding
print_r ($response);
Will write out the raw data, Now i know that am on the right way.
Array returned
{
"data": [
{
"id": "123",
"from": {
"name": "Mathias",
"id": "APP_ID"
},
"start_time": "X",
"end_time": "X",
"publish_time": "X",
"application": {
"name": "APP_Name",
"namespace": "",
"id": "321"
},
"data": {
"object": {
"id": "139",
"url": "Url to like",
"type": "video.tv_show",
"title": "title"
}
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
And then the next..
From every app "like" i would like to display Url ,Title & Image
From what i understand so far my main problem is that this is nested arrays, Did try with single level arrays and there i did manage to display correct data just by
echo $response[name];
So how do i digg in and loop this around, All tips are welcome,
{
"id": "139",
"url": "url",
"type": "video.tv_show",
"title": "titke",
"image": [
{
"url": "image_URL",
"secure_url": "image_URL",
"type": "image/jpg",
"width": 1024,
"height": 576
}
Here's an example:
<?php foreach ( $response['data'] as $data ): ?>
<?php $Object = $data['data']['object']; ?>
<?php echo $Object['title']; ?><br />
<?php endforeach; ?>

Categories