简体   繁体   中英

JSON and file_get_contents

i have really a big problem, i have created a login API, and i'm facing a problem, when i access my website from URL it gives me the Code :

{
  "status": 200,
  "user_data": {
    "username": "",
    "email": "",
    "first_name": "",
    "last_name": "",
    "gender": "",
    "avatar": "",
    "cover": ""
  }
}

That's mean i have successfully received the data, but when i'm trying to get the data via file_get_contents(); it don't work, and start to give me php errors from the sender server:

{
  "errors": {
    "error_id": 2,
    "error": "User not logged in"
  }
}

and that's mean that the user is not logged in, but i'm logged in when i access the URL directly,

the question is how can i generate a JSON data to send it and receive it from another server or domain like Facebook graph, or soundcloud API, they both are working with file_get_contents();

How should your PHP script know, that you are logged in with your browser? Please take a look at oauth2. You have to implement the possibility to authorize your script to get access to the userdata.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM