How to get MySpace profile info using OpenSocial client library? - php

Any advice on how to get MySpace or Orkut info such as birthdate from a person's profile using OAuth using the OpenSocial PHP Client library?
I am lost on the process, and the tutorials are complicated. Any simple code would be helpful!
Thanks.

First, you need the PHP Open Social Client.
As shown in the documentation, you will need to create an osapi container, which requires a provider and an authorization object. In the case of MySpace, it would look something like:
$provider = new osapiMySpaceProvider();
$auth = new osapiOAuth2Legged("<consumer key>", "<consumer secret>", "<OpenSocial user ID>");
$osapi = new osapi($provider, $auth);
I'm afraid I have no idea what goes in the auth area, whether it's those actual strings or something that you should already know. I'm sure the page I got it from has more info. But either way, once you have the osapi container, you can then make requests for user info:
$profile_fields = array(
'aboutMe',
'displayName',
'bodyType',
'currentLocation',
'drinker',
'happiestWhen',
'lookingFor'
);
$self_request_params = array(
'userId' => $userId, // Person we are fetching.
'groupId' => '#self', // #self for one person.
'fields' => $profile_fields // Which profile fields to request.
);
$result = $osapi->people->get($self_request_params), 'self');

Here's a nice tutorial: http://wiki.opensocial.org/index.php?title=Social_Website_Tutorial

Related

Google People API / Method: contactGroups.list

This is the sample code that I am using to get my contacts from Google People API. Works fine.
$people_service = new Google_Service_PeopleService($client); // TODO: Use service object to request People data
$connections = $people_service->people_connections->listPeopleConnections ('people/me',
array('personFields' => 'names,emailAddresses,biographies',
'pageSize' => 25,
'sortOrder' => 'FIRST_NAME_ASCENDING',
));
But I couldn't figure out how to list and manage Contact Groups (like friends, family etc.).
This is the code I am trying without success.
$groups_list = $people_service->contactGroups->listcontactGroups();
Sources I could find:
https://developers.google.com/resources/api-libraries/documentation/people/v1/php/latest/class-Google_Service_PeopleService.html
https://developers.google.com/people/api/rest/v1/contactGroups/list
Have you check if you need to call an extra function as indicated in this documentation? Follow the PHP sample for printing the names for up to 10 connections.
$groups_list = $people_service->contactGroups->listcontactGroups();
$group_list->getContactGroups( );

PHP - How to subscribe user to MailerLite using API

On my website, people can register to become a member. Now I want them to be also immediately be subscribed to my MailerLite mailinglist. In the API documentation I have fount the following PHP example which should work:
$ML_Subscribers = new MailerLite\Subscribers('xxxxxxxxxxxxxxxxxxxxxx');
$subscriber = array(
'email' => $e,
'name' => $f,
);
$subscriber = $ML_Subscribers->setId('xxxxxxxxxxx')->setAutoresponders(false)->add($subscriber);
The API url that's mentioned on their website is the following:
https://app.mailerlite.com/api/v1/subscribers/{list_id}/
I am unsure how to implement this URL in the script.. I have the above PHP code that should add a subscriber to the list, but should I also include the link in some way? I could use some help to make it work. Thanks in advance!
When using the MailerLite SDK it is not required to post to any specific end point. There are wrappers within the functions that dictate the endpoint and method request type when sending data to their API.
The provided code below is all that is required:
$ML_Subscribers = new MailerLite\Subscribers( API_KEY );
$subscriber = array(
'email' => $e,
'name' => $f,
);
$subscriber = $ML_Subscribers->setId( LIST_ID )->setAutoresponders(false)->add( $subscriber );
Where you would replace API_KEY with the provided MailerLite API key, and LIST_ID with the ID of the list that you wish to add the subscriber to.
Otherwise if you weren't using their SDK you would need to make a POST to their endpoint: POST https://app.mailerlite.com/api/v1/subscribers/{list_id}/. You would also be required to construct the proper data object to be sent over containing your API Key, an Email and the id of the subscriber list.
You can read further about this in the MailerLite Documentation

Firebase PHP CURL Authentication

I currently building a small chat using Firebase and PHP. This, I thought, would be a good learning project for Firebase, and so far I am very happy with it!
However, I have hit a wall. I am not sure how I can implement an authentication system to Firebase via PHP. It's quite specific what I need the authentication system to do:
To be able to use the chat, the user must login using my custom php login system. Then once they are logged in, they will also authenticate to be able to read/write in the chat.
I couldn't really understand how this (if even) is possible with PHP, using CURL.
In my __construct function in have the following:
require('/libs/FirebaseLib.php');
$this->firebase = new fireBase('https://<url>.firebaseio.com');
require('/libs/JWT.php');
require('/libs/FirebaseToken.php');
$tokenGen = new Services_FirebaseTokenGenerator('<firebase-secret>');
$this->authtoken = $tokenGen->createToken(
array(
'id' => $this->userid
)
);
How would I authenticate with Firebase to let the user be able to read/write in my chat and not allow non authenticated user to read/write?
Note: I have not done anything to the Firebase security rules - this is part of my question.
I've looked at the documentation, I might just be very thick, but I couldn't really find what I was looking for.
Hope anyone to point me in the right direction.
Thanks!
EDIT: I have intentionally not been using javascript for my chat, apart from ajax calls to my php script which then relays it to Firebase after I have done what I want to do with the user's messages.
EDIT 2: Added links to the used libraries: "Firebase Token Generator" and "Firebase PHP Client"
EDIT 3: My current code looks like this: (reference)
__construct:
$this->authtoken = JWT::encode(
array(
'admin' => true,
'debug' => true,
'v' => 0,
'iat' => time(),
'd' => array('user' => 'admin')
),
'<secret>',
'HS256'
);
New Message Function:
$response = $this->firebase->set('/chat.json?auth=' . $this->authtoken, array(
'message' => array(
'username' => 'Test',
'time' => time(),
'string' => 'Hello World!'
)
));
However it returns: { "error" : "invalid_token: Could not parse auth token." }. I basically want to get permission as the administrator. I have tried just using the Firebase secret as the auth, but its returns the same error.
Rules:
{
"rules": {
".read": "auth.username == 'admin'",
".write": "auth.username == 'admin'"
}
}
The general workflow would be:
After user has authenticated with your custom login system, generate a Firebase auth token in your server-side PHP code. (it looks like you got this far with the code snippet you pasted).
Pass that token back to the client.
Have the client call firebase.auth(<token>); to authenticate to Firebase using your server-generated token.
Use security rules to restrict what the client can read/write, depending on the contents of their auth token.
For a simple scenario where you just want to allow all Firebase access if they're authenticated, you could just have security rules like:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
This would give authenticated users read/write access to your whole Firebase. You probably want to lock it down more than that though (i.e. only give them read/write access to certain parts of the Firebase). Check out our Security Quickstart for a walkthrough on how auth and security rules work.
If this doesn't help, perhaps you can elaborate on which part you're getting stumped at.

Unable to update user full name on Soundcloud, over api access?

Are anyone using Soundcloud.com api and trying to update user[full_name] ?!
I'm developing my own PHP wrapper, but I've tested with the 'Official supported' php wrapper, with no luck too.
Is it possible that 'full_name' is a read-only data field?!
<?php
require_once 'Services/Soundcloud.php';
// create a client object with access token
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// get authrization login
// authorize application, get the CODE here
// ...
// then set the oauth2_token to access 'private' aka logged-in-only resources
$client->setAccessToken('ACCESS_TOKEN');
// get the current user
$user = json_decode($client->get('me'));
// update the user's profile full_name
$user = json_decode($client->put('me', array(
'user[full_name]' => 'John Doe'
)));
print $user->full_name;
When i run this code.. I receive on my cURL handler a HTTP CODE of 200 OK.
but the full name is never updated on soundcloud. I can with the same code update 'description', or 'city' fields.
it's possible that 'full_name' is a read-only?!
Soundcloud documentation is very 'limited' (on lack of better word, english is not my native language) and I can't find there (developers.soundcloud.com) any information regarding 'non-updatable' data fields.
Thanks for your help in advance,
and Sorry for my bad English.

Having trouble with the oauth_verifier for offline use in simple linkedin php

Disclaimer,
Please pardon grammatical syntax.
I'm using the simple linkedin php library that is offered on the linkedin's site. I have followed their instructions and have successfully collected the users oauth-token and oauth-secret. Those 2 pieces of information have been stored in a database. I would like to know how make an offline oauth call, but im having trouble finding more information on the oath-verifier. This is the code that i have so far.
include('../../php/linkedin/linkedin_3.2.0.class.php');
include '../../php/global.settings.php';
$API_CONFIG = array(
'appKey' => LINKEDIN_APP_KEY,
'appSecret' => LINKEDIN_APP_SECRET,
'callbackUrl' => NULL
);
$linkedin = new LinkedIn($API_CONFIG);
$linkedin->request_token = "4e1e5ede-1de4-4eba-ba33-d3d37cbe67ff -FAKE";
$linkedin->access_token = "82b2c333-1075-441b-a51f-657196bf507w -FAKE";
$search_response = $linkedin->search("?company-name=facebook&count=10");
var_dump($search_response);
Temporarily I'm inserting the keys their on my own trying to bottleneck the behavior. Again, the authentication was successful, but my attempt to make a call to the users profile when the user is offline is a failure. I believe it is because im missing the oauth-verifier, but i don't believe that the oauth-verifier is necessary to make an offline call.The code pretty much breaks without any errors (if that is possible). I Have not tempered with the linkedin library nor there are any errors in the global.settings.php.
If you have already stored the user's access token then all you need to do is feed the access token in to the library and make your calls. From the demo file, something along the lines of:
$API_CONFIG = array(
'appKey' => LINKEDIN_APP_KEY,
'appSecret' => LINKEDIN_APP_SECRET,
'callbackUrl' => NULL
);
$linkedin = new LinkedIn($API_CONFIG);
$linkedin->setToken(array(
'oauth_token' => $token,
'oauth_token_secret' => $secret
));
$search_response = $linkedin->search("?company-name=facebook&count=10");
var_dump($search_response);

Categories