Pusher chat kit tutorial not working as expected - ios

I want to create a simple chat app demo using pusher chat kit.
I am following the pusher provided tutorial .I am following documentation as it is but its not working in my case .
According to pusher documentation Chatmanger class object should be instantiated as follow:
chatManager = ChatManager(
instanceLocator: "YOUR INSTANCE LOCATOR",
tokenProvider: PCTokenProvider(url: "YOUR TEST TOKEN ENDPOINT"),
userId: "YOUR USER ID"
)
but in my case when i follow same code in my demo project there is an error appeared with following parameter correction Error .
I don't know Where i am doing wrong .

What you have to do is create an account in https://pusher.com/, and then create
and a chatkitt instance.
Now you have an account and chatkit instance. To acces The chatkit instance from your .js using:
const chatkit = new Chatkit.default({
instanceLocator: "PUSHER_CHATKIT_INSTANCE_LOCATOR",
key: "PUSHER_CHATKIT_KEY"
})
PUSHER_CHATKIT_INSTANCE_LOCATOR: it's a string that you can see in pusher inside your account, it's a unique.
Additionally, you have the PUSHER_CHATKIT_KEY it's string and unique too.
both them (PUSHER_CHATKIT_INSTANCE_LOCATOR, and key), has to replace in the code above by the strings provided in your account.
i will leave you the tutorial about this step in this link:
https://pusher.com/tutorials/chat-widget-javascript#create-your-chatkit-instance

Related

Can't get any account info, or review info

I've tried for hours now to figure this out but I'm completely stuck.
I have been approved for My Business APi and I created a service account and downloaded the json file for authentication.
I am using google-api-php-client and with google-api-my-business-php-client which provides the 'Google_Service_MyBusiness' class for use.
My code looks like this: -
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/google-api-my-business-php-client/MyBusiness.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/myfile.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
if (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
} else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName("my_app");
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$service = new Google_Service_MyBusiness($client);
$accounts = $service->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
But all that I ever get back is
Google_Service_Exception: That’s an error. The requested URL <code>/v3/accounts</code> was not found on this server. That’s all we know.
I notice that the documentation is now v4, i.e. v4/accounts, could this be the issue? Are these libraries out of date? How can I retrieve account and review data with v3?
Any help would be appreciated.
My end goal is the retrieve all the reviews for a location but right now just trying to get this to work as a prelude.
Answering my own question - I think the main issue is it turns out that My Business api doesn't support service accounts, you need to use oauth2.
Turns out that V3 is depreciated also so the libray I was using for MyBusiness API is useless, the other one works fine for updating access tokens.
For the reviews I am just using Curl and Simply building the URL with the ?access-token= value on the end of it.
For example to list all reviews
https://mybusiness.googleapis.com/v4/accounts/[acc-number]/locations/[location-id]/reviews?access_token=

Did anyone manage to get the id token from google sign in (Flutter)

I am trying to connect my users with my back end server , i used the example from the official google sign in plugin for flutter :
https://pub.dartlang.org/packages/google_sign_in
the sign process goes fine and i get the username and email ect..
but i need the id Token to authenticate the user with my server.
Ps: Not using firebase , only google sign in.
Can anyone guide me how to get the id Token ?
You can try using this
_googleSignIn.signIn().then((result){
result.authentication.then((googleKey){
print(googleKey.accessToken);
print(googleKey.idToken);
print(_googleSignIn.currentUser.displayName);
}).catchError((err){
print('inner error');
});
}).catchError((err){
print('error occured');
});
You can get access token and id token more simple like this:
final result = await _googleSignIn.signIn();
final ggAuth = await result.authentication;
print(ggAuth.idToken);
print(ggAuth.accessToken);
Or you also can add it to try-catch to handle an error.
try {
final result = await _googleSignIn.signIn();
final ggAuth = await result.authentication;
print(ggAuth.idToken);
print(ggAuth.accessToken);
} catch (error) {
print(error);
}
or try like this if id token was null, it worked for me.
As the docs point out you need oauth2 client id of your backend to request idToken or serverAuthCode.
from firebase google sigin in authentication copy the Web SDK configuration
add paste in the following to res/values/strings.xml, That should work
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id">{Web app Client id goes here}</string>
</resources>
The issue may be related to not using firebase. There is a google-services.json file which is given to you when you register your app in firebase, and you can use that with google_sign_in (this is the default way shown in the documentation).
I was getting null for the token value when trying to implement this without the google-services.json, but successfully signing into google.
If you don't want to use firebase, you have to jump through a couple hoops.
In google cloud console, register your app.
Then make sure you are 'in' your app that you just created in the top drop down menu.
in "apis and services" in the sidebar menu, go through the create Oauth consent screen menu, I don't remember having to fill out many fields, so leave them blank if you don't know what to put in.
then go to the "credentials" menu in the sidebar, and click "Create New Credentials", and select OAuth2 client ID. Make a web client, even though you're trying to use it with an android/ios app.
Make a file android/app/src/main/res/values/strings.xml
using the web client we just made, insert <?xml version="1.0" encoding="utf-8"?> <resources> <string name="default_web_client_id">YOUR WEB CLIENT ID</string> </resources> into the strings.xml file.
[edit] make one more client in the google console for android, and put in your local machine's sha1 key. This step is done for you automatically if you're using firebase. In this case, you have to create both the web client and one for your android device. In production, you'd be using a specific client for your production app.
That should do it I believe, might have missed a step.
I also wanted to verify on my backend that the incoming idtoken was valid, so I had to also make a service account (in the apis and services -> credentials page) and use that in my go server.
I'm still struggling to get this to work with ios, but the android side works great.
To retrieve the Is idToken worked for me:
1. The google-services.json file must be placed in /android/app/
2. you need to add to your /android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
3. and to /android/build.gradle
classpath 'com.google.gms:google-services:4.3.4'
And that's it. GoogleSignIn will return a real idToken instead of null.
font: https://github.com/flutter/flutter/issues/12140#issuecomment-348720774
One more clean way to achieve this:
late Map<String, dynamic> userObject = {};
var res = await _googleSignIn.signIn();
var googleKey = await res!.authentication;
userObject.addAll({
'accessToken': googleKey.accessToken,
'idToken': googleKey.idToken,
'displayName': res.displayName ?? '',
'email': res.email,
'id': res.id,
'avatarUrl': res.photoUrl ?? '',
'serverAuthCode': res.serverAuthCode ?? '',
});
I was struggling with this issue for about a month. Turns out I was getting the same access token, even when the user tried restarting the app. This was painful because my app dealt with scopes and in case a user misses to check one or more scopes in his first sign in, the app wouldn't work at all, even if he/she signs in again and gives the permissions.
Workaround which worked for me: I called the googleSignIn.currentUser.clearAuthCache() method followed by googleSignIn.signInSilently(). This returns a GoogleSignInAccount which can be used for further authentication. My guess is that the clearAuthCache() method clears the token cache and hence a new token is created. This should get you a new access token and let your app make valid calls.
I sincerely request Google developers to solve this issue. For now, this workaround is the only thing that worked.
Try this:
When you create your GoogleSignIn object:
GoogleSignIn(
clientId: "YOUR CLIENT ID"
)
i hope it helps ;)

How do you register a new user (with attributes) in Hyperledger Fabric Client (HFC)?

I am reviewing the sample code for the HFC SDK and saw ways to manage users.
To enroll an existing user the following function is used:
chain.enroll
To register and enroll a new user the following function is used:
chain.registerAndEnroll
However, the sample code did not provide an example for a register only function:
chain.register
If I understand it correctly both the chain.enroll and chain.registerAndEnroll will both save the user key/certificate in the machine where the functions are called.
If I want an admin to create a new user (e.g., userA), I cannot use the chain.registerAndEnroll function since the key/certificate will be saved in the admin's machine instead of userA's machine since the function performs not only a register but also an enroll. Hence, my need for a register only function.
In addition, how do I add attributes to users using HFC similar to the attributes that can be defined in membersrvc.yaml?
Unfortunately I was unable to find an online link to the hfc API doc (although you can build the doc locally if needed).
That being said, there is a chain.register function which takes a RegistrationRequest object and then returns the enroll secret/password you would later use to enroll the new user:
//create some attributes
var attributes = [{name:'foo',value:'bar'}];
var registrationRequest = {
roles: [ role ],
enrollmentID: name,
affiliation: "bank_a",
attributes: attributes,
registrar: registrar
};
chain.register(registrationRequest, function(err, enrollmentPassword) {
//your code here
}

I can't seem to get the first Twitter4J code example (Simple post on Twitter) to work. UpdateStatus(string) is undefined

So this is my problem right now:
I went to http://twitter4j.org/en/code-examples.html as I just started to use twitter4j (version 4.0.2 as far as I can remember) and I wanted to try to code examples to get a basic understanding of T4J.
However, it seems like I can't even get the first example to work. This is my code right now:
import twitter4j.Status;
import twitter4j.TwitterFactory;
public class Twitter {
public static void main(String[] args) {
String latestStatus="Test";
Twitter twitter = (Twitter) TwitterFactory.getSingleton();
Status status = twitter.updateStatus(latestStatus);
System.out.println("Successfully updated the status to [" + status.getText() + "].");
}
}
This is exactly to code I found on code examples (Plus the string which should end up being the status). However, I always get an error at Status status=twitter.updateStatus(latestStatus), which is basically this:
The method updateStatus(String) is undefined for the type Twitter
I have literally no idea what could be wrong here. I mean in the end it's the official code example. Even the official doc is using strings as parameter for that method.
Can anyone give me a helping hand?
Thanks in advance.
You need couple of things to make this code work -
First you need to register your app with Twitter and generate OAuth Authentication. You will get following - consumerkey, consumersecret, accesstoken and accesstokensecret.
Using the keys and secret you would create a Twitter instance, which you can use to access your Twitter User ID.
Second you need to authorize your app to be able to write updates default permission is Read Only.
You can register and manage your app at https://apps.twitter.com/
Also about the twitter$j library version, please use a latest one.
Here is a code snippet to use the authentication keys and update the status -
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("consumerKey")
.setOAuthConsumerSecret("consumerSecret")
.setOAuthAccessToken("accessToken")
.setOAuthAccessTokenSecret("accessTokenSecret");
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Status status = twitter.updateStatus("test");
Hope this is helpful.
This is happening because your class is called Twitter, so
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
will be interpreted as you trying to create an instance of your class Twitter, rather than an instance of twitter4j.Twitter. You could change the name of your class to something else, or change the library Twitter instances to twitter4j.Twitter instances to specify the difference.

Test Webhook at localhost in braintree

I am working on braintree and I want to send custom email notifications to my customers as I am working with recurring billing, so every month these custom notifications should be send to all users. For this I have to use webhooks to retrieve currently ocuured event and then send email notification according to webhook's response. (I think this is only solution in this case, If anyone know another possible solution please suggest). I want to test webhooks at my localhost first, And I have tried to create a new webhook and specified the localhost path as destination to retrieve webhooks. But this shows a error "Destination is not verified"..........
My path is : "http://127.0.0.1:81/webhook/Accept"
These are some of the tools that can be used during development of webhooks :
1) PostCatcher,
2) RequestBin,
3) ngrok,
4) PageKite and
5) LocalTunnel
http://telerivet.com/help/api/webhook/testing
https://www.twilio.com/blog/2013/10/test-your-webhooks-locally-with-ngrok.html
Well Another way to test it is by creating a WebAPI and POSTing Data to your POST method via Postman. To do this, just create a WebAPI in Visual Studio. In the API controller, create a POST method.
/// <summary>
/// Web API POST method for Braintree Webhook request
/// The data is passed through HTTP POST request.
/// A sample data set is present in POSTMAN HTTP Body
/// /api/webhook
/// </summary>
/// <param name="BTRequest">Data from HTTP request body</param>
/// <returns>Webhook notification object</returns>
public WebhookNotification Post([FromBody]Dictionary<String, String> BTRequest)
{
WebhookNotification webhook = gateway.WebhookNotification.Parse(BTRequest["bt_signature"], BTRequest["bt_payload"]);
return webhook;
}
In Postman, Post the following data in the Body as raw JSON.
{
"bt_signature":"Generated Data",
"bt_payload":"Very long generated data"
}
The data for the above Json dictionary has been generated through the below code:
Dictionary<String, String> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.DISPUTE_OPENED, "my_Test_id");
// Your Webhook kind and your test ID
Just pick the data from sample notification and place it above in the JSON. Run your WebAPI, place debuggers. Add the localhost URL in Postman, select POST, and click on Send.
Your POST method should be hit.
Also, don't forget to add your gateway details:
private BraintreeGateway gateway = new BraintreeGateway
{
Environment = Braintree.Environment.SANDBOX,
MerchantId = "Your Merchant Key",
PublicKey = "Your Public Key",
PrivateKey = "Your Private Key"
};
I hope this helps!
I work at Braintree. If you need more help, please get in touch with our support team.
In order to test webhooks, your app needs to be able to be reached by the Braintree Gateway. A localhost address isn't. Try using your external IP address and make sure the port on the correct computer can be reached from the internet.
Take a look at the Braintree webhook guide for more info on setting up webhooks.
You can use PutsReq to simulate the response you want and do your end-to-end test in development.
For quick 'n dirty testing:
http://requestb.in/
For more formal testing (e.g. continuous integration):
https://www.runscope.com/
If you have a online server you may forward port from your computer to that server.
ssh -nNT -R 9090:localhost:3000 root#yourvds.com
And then specify webhook as http://yourvds.com:9090/webhook
all requests will be forwarded to you machine, you will be able to see logs
I know this is an old question, but according to the docs, you can use this code to test your webhook code:
Dictionary<String, String> sampleNotification = gateway.WebhookTesting.SampleNotification(
WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id"
);
WebhookNotification webhookNotification = gateway.WebhookNotification.Parse(
sampleNotification["bt_signature"],
sampleNotification["bt_payload"]
);
webhookNotification.Subscription.Id;
// "my_id"
You can use the Svix CLI Listener: https://github.com/svix/svix-cli#using-the-listen-command
This will allow you to easily channel requests to your public endpoint to a local port where you can run your logic against and debug it on your localhost.

Resources