PHP - How to subscribe user to MailerLite using API - php

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

Related

PayPal IPN POST results in 0 PHP Laravel

I'm struggling with a simple storage script that should be called via PayPal IPN to save the current payment.
I'm using
$input = json_encode($request->all());
$paylog = Paylog::create([
'data' => $input,
]);
and the result from any incoming POST is always "0".
Where is my fault?
Perhaps you mean to access $_POST
IPN messages should be verified with a postback to ipnpb.paypal.com before doing anything with their contents
IPN is a very old and clunky technology, why are you using it?
To obtain details on a 'current' payment, you should be using an API like v2/checkout/orders to facilitate the checkout. For this you need two routes on your server, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
The best approval flow to pair with your two routes is https://developer.paypal.com/demo/checkout/#/pattern/server
Solution:
//Make sure encode values to UTF8
$input = json_encode(array_map('utf8_encode',$request->all()));
//And store
$paylog = Paylog::create([
'data' => $input,
]);
Or to make things a little more efficient:
$paylog = Paylog::create([
'data' => $json_encode(array_map('utf8_encode',$request->all())),
]);

ebay sdk - retrieving orders and sync with external DB

I am struggling, literally, trying to figure out how to use th Ebay API in order to retrieve the orders received on a specific merchant account and then store some datas in an external DB.
I have registered to developer.ebay.it, I have built a key pair, both for production and sandbox, then I have tried the api (Browse/getItem)...and then...LOST.
I cannot use the Fullfillment, because I always get a response of Insufficient authorization, even if I create a token, even if I put a real order number... I don't get how to question the API.
Lastly, I am using PHP and I have downloaded the davidtsadler SDK from github. How do I configure an example of getOrder with that SDK? Do you have any link, suggestions, anything?
What I find on internet is not enough clear for my level of knowledge and almost nobody deals with the getOrder call.
Thank you for your help.
The ebay API documentation is fairly clear on how to perform a query:
If you wanted to get a specific Fullfillment policy, then you would need to perform a GET request to ebays Fullfillment API using the /order/{orderId} path - where {orderId} is a real order ID.
In PHP, that might go a little something like this:
/* Returns a JSON object containing an ebay order */
function getOrder($order_id, $auth_key){
$options = array(
'http' => array(
'method' => "GET",
'header' => "Authorization: Bearer ".$auth_key."\r\n" .
"Content-Type: application/json"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.ebay.com/sell/fulfillment/v1/order/".$order_id, false, $context);
return json_decode($result);
}
Then you could call the method above and retrieve an order using:
$order = getOrder("A REAL ORDER ID", "YOUR AUTH KEY");
The $order variable now holds a JSON object. You can print info from the object using: (This example prints the username associated with the order)
echo $order->buyer->username;
Finally, please note the direct quote from ebays documentation:
"eBay creates and displays an Application token. This token is valid for a limited time span. If you get an invalid token error when you make a call using this token, simply create a new token and use the new token in your call."

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( );

Laravel send tweet as user

Is it possible to send automatic tweets from laravel like user.
User must be logged by my twitter API, and then can I send tweet as him?Of course he must accept this action. I must know when user tweets my page.
Can it work like facebook share? Is there tools for this?
Sorry for my english.
Thanks for all answer.
PS.
I do not mean this package http://vegibit.com/send-a-tweet-with-laravel/ .
I need send tweets to user table.
I have found the ThuJohn package to be the winner at this type of work.
https://github.com/thujohn/twitter
Simple to use with various options, such as
Send a tweet realtime without media:
Route::get('/send-tweet-no-media', function()
{
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'format' => 'json']);
});
Send a tweet realtime with media:
Route::get('/send-tweet-with-media', function()
{
$uploaded_media = Twitter::uploadMedia(['media' => File::get(public_path('filename.jpg'))]);
return Twitter::postTweet(['status' => 'Laravel is beautiful', 'media_ids' => $uploaded_media->media_id_string]);
});
You can also do various other things, such as login, You can take it an extra level and easily store the users token & secret to your users table and do scheduled posts.
Once you have stored the users token & secret you can tweet scheduled posted for them like this:
//Get the Users token & from your User Table (or where ever you stored them)
$token = $user->token;
$secret = $user->secret;
//This line resets the token & secret with the users
Twitter::reconfig(['token' => $token, 'secret' => $secret]);
//This line posts the tweet as the user
Twitter::postTweet(['status' => 'test', 'format' => 'json']);
Use this https://twitteroauth.com/ package.
Push in your console composer require abraham/twitteroauth
When all installed then you should add
use Abraham\TwitterOAuth\TwitterOAuth; to your class.
Now in function you must create connection with your api.
$connection = new TwitterOAuth(
CONSUMER_KEY, // Information about your twitter API
CONSUMER_SECRET, // Information about your twitter API
$access_token, // You get token from user, when him sigin to your app by twitter api
$access_token_secret// You get tokenSecret from user, when him sigin to your app by twitter api
);
If you created connection then you can send post as user.
For example:
$connection->post("statuses/update", ["status" => "My first post!"]);

How to get MySpace profile info using OpenSocial client library?

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

Categories